@@ -66,7 +66,10 @@ public function parseToken()
6666
6767 public function login (Authenticatable $ user )
6868 {
69- $ token = $ this ->jwtManager ->make (['uid ' => $ user ->getId ()])->token ();
69+ $ token = $ this ->jwtManager ->make ([
70+ 'uid ' => $ user ->getId (),
71+ 's ' => str_random (),
72+ ])->token ();
7073
7174 Context::set ($ this ->resultKey ($ token ), $ user );
7275
@@ -81,15 +84,15 @@ public function login(Authenticatable $user)
8184 */
8285 public function resultKey ($ token )
8386 {
84- return $ this ->name . '.auth.result. ' . $ this ->getJti ($ token );
87+ return $ this ->name . '.auth.result ' . $ this ->getJti ($ token );
8588 }
8689
8790 public function user (?string $ token = null ): ?Authenticatable
8891 {
8992 $ token = $ token ?? $ this ->parseToken ();
9093 if (Context::has ($ key = $ this ->resultKey ($ token ))) {
9194 $ result = Context::get ($ key );
92- if ($ result instanceof \Throwable ) {
95+ if ($ result instanceof UnauthorizedException ) {
9396 throw $ result ;
9497 }
9598 return $ result ?: null ;
@@ -141,7 +144,7 @@ public function guest(?string $token = null): bool
141144 */
142145 public function refresh (?string $ token = null ): ?string
143146 {
144- $ token = $ token ?? $ this ->parseToken ();
147+ $ token = $ token ?: $ this ->parseToken ();
145148
146149 if ($ token ) {
147150 Context::set ($ this ->resultKey ($ token ), null );
@@ -180,13 +183,13 @@ public function getJwtManager(): JWTManager
180183 /**
181184 * 获取 token 标识.
182185 *
183- * @throws \Qbhy\SimpleJwt\Exceptions\TokenExpiredException
184186 * @throws \Qbhy\SimpleJwt\Exceptions\InvalidTokenException
185187 * @throws \Qbhy\SimpleJwt\Exceptions\SignatureException
188+ * @throws \Qbhy\SimpleJwt\Exceptions\TokenExpiredException
186189 * @return mixed|string
187190 */
188191 protected function getJti (string $ token ): string
189192 {
190- return $ this ->getJwtManager ()->parse ($ token )->getPayload ()['jti ' ] ?? md5 ($ token );
193+ return $ this ->getJwtManager ()->justParse ($ token )->getPayload ()['jti ' ] ?? md5 ($ token );
191194 }
192195}
0 commit comments