From a3fc7b98909f8481641bd5e55a6bd58415d2bae7 Mon Sep 17 00:00:00 2001 From: Aman Nurani Date: Mon, 29 Jul 2019 13:10:20 +0530 Subject: [PATCH] Changes in token refresh method --- src/JWT.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/JWT.php b/src/JWT.php index 55d14e235..172d35744 100644 --- a/src/JWT.php +++ b/src/JWT.php @@ -101,10 +101,14 @@ public function fromUser(JWTSubject $user) public function refresh($forceForever = false, $resetClaims = false) { $this->requireToken(); + $this->manager->setRefreshFlow(); - return $this->manager->customClaims($this->getCustomClaims()) - ->refresh($this->token, $forceForever, $resetClaims) - ->get(); + if (!$user = $this->authenticate()) { + throw new UnauthorizedHttpException('jwt-auth', 'User not found'); + } + return $this->manager->customClaims($this->getClaimsArray($user)) + ->refresh($this->token, $forceForever, $resetClaims) + ->get(); } /** @@ -181,7 +185,7 @@ public function getToken() */ public function parseToken() { - if (! $token = $this->parser->parseToken()) { + if (!$token = $this->parser->parseToken()) { throw new JWTException('The token could not be parsed from the request'); } @@ -246,7 +250,7 @@ protected function getClaimsArray(JWTSubject $subject) return array_merge( $this->getClaimsForSubject($subject), $subject->getJWTCustomClaims(), // custom claims from JWTSubject method - $this->customClaims // custom claims from inline setter + $this->customClaims// custom claims from inline setter ); } @@ -327,7 +331,7 @@ public function unsetToken() */ protected function requireToken() { - if (! $this->token) { + if (!$this->token) { throw new JWTException('A token is required'); } }