Add strict return types to TokenService
This commit is contained in:
parent
a7ebc9a24f
commit
8ac32f5783
1 changed files with 8 additions and 3 deletions
|
@ -1,8 +1,11 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use RuntimeException;
|
||||
use Lcobucci\JWT\Token;
|
||||
use Lcobucci\JWT\Parser;
|
||||
use Lcobucci\JWT\Builder;
|
||||
use InvalidArgumentException;
|
||||
|
@ -27,7 +30,7 @@ class TokenService
|
|||
->sign($signer, config('app.key'))
|
||||
->getToken();
|
||||
|
||||
return $token;
|
||||
return (string) $token;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,17 +39,19 @@ class TokenService
|
|||
* @param string The token
|
||||
* @return mixed
|
||||
*/
|
||||
public function validateToken($token)
|
||||
public function validateToken(string $token): ?Token
|
||||
{
|
||||
$signer = new Sha256();
|
||||
try {
|
||||
$token = (new Parser())->parse((string) $token);
|
||||
} catch (InvalidArgumentException | RuntimeException $e) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
if ($token->verify($signer, config('app.key'))) {
|
||||
//signuture valid
|
||||
return $token;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue