@@ -66,7 +66,7 @@ public function parseToken()
6666
6767 public function login (Authenticatable $ user )
6868 {
69- $ token = $ this ->jwtManager ->make ([
69+ $ token = $ this ->getJwtManager () ->make ([
7070 'uid ' => $ user ->getId (),
7171 's ' => str_random (),
7272 ])->token ();
@@ -100,7 +100,7 @@ public function user(?string $token = null): ?Authenticatable
100100
101101 try {
102102 if ($ token ) {
103- $ jwt = $ this ->jwtManager ->parse ($ token );
103+ $ jwt = $ this ->getJwtManager () ->parse ($ token );
104104 $ uid = $ jwt ->getPayload ()['uid ' ] ?? null ;
105105 $ user = $ uid ? $ this ->userProvider ->retrieveByCredentials ($ uid ) : null ;
106106 Context::set ($ key , $ user ?: 0 );
@@ -150,14 +150,14 @@ public function refresh(?string $token = null): ?string
150150 Context::set ($ this ->resultKey ($ token ), null );
151151
152152 try {
153- $ jwt = $ this ->jwtManager ->parse ($ token );
153+ $ jwt = $ this ->getJwtManager () ->parse ($ token );
154154 } catch (TokenExpiredException $ exception ) {
155155 $ jwt = $ exception ->getJwt ();
156156 }
157157
158- $ this ->jwtManager ->addBlacklist ($ jwt );
158+ $ this ->getJwtManager () ->addBlacklist ($ jwt );
159159
160- return $ this ->jwtManager ->refresh ($ jwt )->token ();
160+ return $ this ->getJwtManager () ->refresh ($ jwt )->token ();
161161 }
162162
163163 return null ;
@@ -167,8 +167,8 @@ public function logout($token = null)
167167 {
168168 if ($ token = $ token ?? $ this ->parseToken ()) {
169169 Context::set ($ this ->resultKey ($ token ), null );
170- $ this ->jwtManager ->addBlacklist (
171- $ this ->jwtManager ->parse ($ token )
170+ $ this ->getJwtManager () ->addBlacklist (
171+ $ this ->getJwtManager () ->parse ($ token )
172172 );
173173 return true ;
174174 }
@@ -182,14 +182,15 @@ public function getJwtManager(): JWTManager
182182
183183 /**
184184 * 获取 token 标识.
185+ * 为了性能,直接 md5.
185186 *
187+ * @throws \Qbhy\SimpleJwt\Exceptions\TokenExpiredException
186188 * @throws \Qbhy\SimpleJwt\Exceptions\InvalidTokenException
187189 * @throws \Qbhy\SimpleJwt\Exceptions\SignatureException
188- * @throws \Qbhy\SimpleJwt\Exceptions\TokenExpiredException
189190 * @return mixed|string
190191 */
191192 protected function getJti (string $ token ): string
192193 {
193- return $ this -> getJwtManager ()-> justParse ( $ token )-> getPayload ()[ ' jti ' ] ?? md5 ($ token );
194+ return md5 ($ token );
194195 }
195196}
0 commit comments