Add strict return types to TokenService

This commit is contained in:
Jonny Barnes 2017-03-01 17:37:21 +00:00
parent a7ebc9a24f
commit 8ac32f5783

View file

@ -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;
}
}