diff --git a/src/JWTTools.php b/src/JWTTools.php index 900faac..2a35370 100644 --- a/src/JWTTools.php +++ b/src/JWTTools.php @@ -13,6 +13,7 @@ use stdClass; use yii\db\ActiveRecord; use yii\helpers\BaseStringHelper; +use yii\web\UnauthorizedHttpException; final class JWTTools { @@ -111,10 +112,6 @@ public function withModel(ActiveRecord $model, array $attributes = []): self return $this; } - /** - * @return string - * @throws Exception - */ public function getJWT(): string { try { @@ -125,18 +122,16 @@ public function getJWT(): string $this->payload->get('sub') ); } catch (ExpiredException $e) { + throw new UnauthorizedHttpException('Authentication token is expired.'); } } - /** - * @param string $token - * @return stdClass - */ public function decodeToken(string $token): stdClass { try { return JWT::decode($token, $this->secretKey, [$this->algorithm]); } catch (ExpiredException $e) { + throw new UnauthorizedHttpException('Authentication token is expired.'); } }