0 follower

Final Class Yiisoft\Auth\Jwt\TokenRepository

InheritanceYiisoft\Auth\Jwt\TokenRepository
ImplementsYiisoft\Auth\Jwt\TokenRepositoryInterface

Token repository is getting a list of claims for a token.

The token JWS is being verified before doing so.

Method Details

Hide inherited methods

__construct() public method
public mixed __construct ( Yiisoft\Auth\Jwt\KeyFactoryInterface $keyFactory, \Jose\Component\Core\AlgorithmManager $algorithmManager, \Jose\Component\Signature\Serializer\JWSSerializerManager $serializerManager )
$keyFactory Yiisoft\Auth\Jwt\KeyFactoryInterface

A factory to create a JSON Web Key.

$algorithmManager \Jose\Component\Core\AlgorithmManager

Algorithms manager for signing JSON Web Signature.

$serializerManager \Jose\Component\Signature\Serializer\JWSSerializerManager

JSON Web Signature serializer manager.

                public function __construct(
    private readonly KeyFactoryInterface $keyFactory,
    private readonly AlgorithmManager $algorithmManager,
    private readonly JWSSerializerManager $serializerManager
) {
}

            
getClaims() public method

public array|null getClaims ( string $token, string|null &$format null )
$token string
$format string|null

                public function getClaims(string $token, ?string &$format = null): ?array
{
    try {
        $jws = $this->serializerManager->unserialize($token, $format);
    } catch (\InvalidArgumentException) {
        return null;
    }
    $jwk = $this->keyFactory->create();
    foreach ($this->algorithmManager->list() as $index => $_algorithm) {
        /** @var int $index */
        if ($this->verifyToken($jws, $jwk, $index)) {
            /** @var array<array-key, mixed>|null */
            return Json::decode($jws->getPayload() ?? '');
        }
    }
    return null;
}