33namespace CodeIgniter \Shield \Models ;
44
55use CodeIgniter \Model ;
6+ use CodeIgniter \Shield \Authentication \Authenticators \AccessTokens ;
7+ use CodeIgniter \Shield \Authentication \Authenticators \Session ;
68use CodeIgniter \Shield \Authentication \Passwords ;
79use CodeIgniter \Shield \Entities \AccessToken ;
810use CodeIgniter \Shield \Entities \User ;
@@ -59,7 +61,7 @@ public function createEmailIdentity(User $user, array $credentials): void
5961
6062 $ return = $ this ->insert ([
6163 'user_id ' => $ user ->id ,
62- 'type ' => ' email_password ' ,
64+ 'type ' => Session:: ID_TYPE_EMAIL_PASSWORD ,
6365 'secret ' => $ credentials ['email ' ],
6466 'secret2 ' => $ passwords ->hash ($ credentials ['password ' ]),
6567 ]);
@@ -119,7 +121,7 @@ public function generateAccessToken(User $user, string $name, array $scopes = ['
119121 helper ('text ' );
120122
121123 $ return = $ this ->insert ([
122- 'type ' => ' access_token ' ,
124+ 'type ' => AccessTokens:: ID_TYPE_ACCESS_TOKEN ,
123125 'user_id ' => $ user ->id ,
124126 'name ' => $ name ,
125127 'secret ' => hash ('sha256 ' , $ rawToken = random_string ('crypto ' , 64 )),
@@ -141,7 +143,7 @@ public function generateAccessToken(User $user, string $name, array $scopes = ['
141143 public function getAccessTokenByRawToken (string $ rawToken ): ?AccessToken
142144 {
143145 return $ this
144- ->where ('type ' , ' access_token ' )
146+ ->where ('type ' , AccessTokens:: ID_TYPE_ACCESS_TOKEN )
145147 ->where ('secret ' , hash ('sha256 ' , $ rawToken ))
146148 ->asObject (AccessToken::class)
147149 ->first ();
@@ -150,7 +152,7 @@ public function getAccessTokenByRawToken(string $rawToken): ?AccessToken
150152 public function getAccessToken (User $ user , string $ rawToken ): ?AccessToken
151153 {
152154 return $ this ->where ('user_id ' , $ user ->id )
153- ->where ('type ' , ' access_token ' )
155+ ->where ('type ' , AccessTokens:: ID_TYPE_ACCESS_TOKEN )
154156 ->where ('secret ' , hash ('sha256 ' , $ rawToken ))
155157 ->asObject (AccessToken::class)
156158 ->first ();
@@ -164,7 +166,7 @@ public function getAccessToken(User $user, string $rawToken): ?AccessToken
164166 public function getAccessTokenById ($ id , User $ user ): ?AccessToken
165167 {
166168 return $ this ->where ('user_id ' , $ user ->id )
167- ->where ('type ' , ' access_token ' )
169+ ->where ('type ' , AccessTokens:: ID_TYPE_ACCESS_TOKEN )
168170 ->where ('id ' , $ id )
169171 ->asObject (AccessToken::class)
170172 ->first ();
@@ -177,7 +179,7 @@ public function getAllAccessTokens(User $user): array
177179 {
178180 return $ this
179181 ->where ('user_id ' , $ user ->id )
180- ->where ('type ' , ' access_token ' )
182+ ->where ('type ' , AccessTokens:: ID_TYPE_ACCESS_TOKEN )
181183 ->orderBy ($ this ->primaryKey )
182184 ->asObject (AccessToken::class)
183185 ->findAll ();
@@ -267,7 +269,7 @@ public function deleteIdentitiesByType(User $user, string $type): void
267269 public function revokeAccessToken (User $ user , string $ rawToken ): void
268270 {
269271 $ return = $ this ->where ('user_id ' , $ user ->id )
270- ->where ('type ' , ' access_token ' )
272+ ->where ('type ' , AccessTokens:: ID_TYPE_ACCESS_TOKEN )
271273 ->where ('secret ' , hash ('sha256 ' , $ rawToken ))
272274 ->delete ();
273275
@@ -280,7 +282,7 @@ public function revokeAccessToken(User $user, string $rawToken): void
280282 public function revokeAllAccessTokens (User $ user ): void
281283 {
282284 $ return = $ this ->where ('user_id ' , $ user ->id )
283- ->where ('type ' , ' access_token ' )
285+ ->where ('type ' , AccessTokens:: ID_TYPE_ACCESS_TOKEN )
284286 ->delete ();
285287
286288 $ this ->checkQueryReturn ($ return );
@@ -290,7 +292,7 @@ public function fake(Generator &$faker): UserIdentity
290292 {
291293 return new UserIdentity ([
292294 'user_id ' => fake (UserModel::class)->id ,
293- 'type ' => ' email_password ' ,
295+ 'type ' => Session:: ID_TYPE_EMAIL_PASSWORD ,
294296 'name ' => null ,
295297 'secret ' => 'info@example.com ' ,
296298 'secret2 ' => password_hash ('secret ' , PASSWORD_DEFAULT ),
0 commit comments