0 follower

Final Class Yiisoft\Auth\Jwt\JwtMethod

InheritanceYiisoft\Auth\Jwt\JwtMethod
ImplementsYiisoft\Auth\AuthenticationMethodInterface

Authentication method based on JWT token.

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( \Yiisoft\Auth\IdentityRepositoryInterface $identityRepository, Yiisoft\Auth\Jwt\TokenRepositoryInterface $tokenRepository, \Jose\Component\Checker\ClaimChecker[]|null $claimCheckers null )
$identityRepository \Yiisoft\Auth\IdentityRepositoryInterface

Repository to get identity from.

$tokenRepository Yiisoft\Auth\Jwt\TokenRepositoryInterface

Token manager to obtain claims from.

$claimCheckers \Jose\Component\Checker\ClaimChecker[]|null

Claim checkers. If not specified, {@see \Jose\Component\Checker\ExpirationTimeChecker} is used.

                public function __construct(
    private IdentityRepositoryInterface $identityRepository,
    private TokenRepositoryInterface $tokenRepository,
    ?array $claimCheckers = null
) {
    $this->claimCheckers = $claimCheckers ?? [new ExpirationTimeChecker()];
}

            
authenticate() public method

public \Yiisoft\Auth\IdentityInterface|null authenticate ( \Psr\Http\Message\ServerRequestInterface $request )
$request \Psr\Http\Message\ServerRequestInterface

                public function authenticate(ServerRequestInterface $request): ?IdentityInterface
{
    $token = $this->getAuthenticationToken($request);
    if ($token === null) {
        return null;
    }
    $claims = $this->tokenRepository->getClaims($token, $name);
    if ($claims === null || !isset($claims[$this->identifier])) {
        return null;
    }
    $this
        ->getClaimCheckerManager()
        ->check($claims);
    return $this->identityRepository->findIdentity((string)$claims[$this->identifier]);
}

            
challenge() public method

public \Psr\Http\Message\ResponseInterface challenge ( \Psr\Http\Message\ResponseInterface $response )
$response \Psr\Http\Message\ResponseInterface

                public function challenge(ResponseInterface $response): ResponseInterface
{
    return $response->withHeader(Header::WWW_AUTHENTICATE, "{$this->headerName} realm=\"{$this->realm}\"");
}

            
withHeaderName() public method

public self withHeaderName ( string $headerName )
$headerName string

Authorization header name.

                public function withHeaderName(string $headerName): self
{
    $new = clone $this;
    $new->headerName = $headerName;
    return $new;
}

            
withHeaderTokenPattern() public method

public self withHeaderTokenPattern ( string $headerTokenPattern )
$headerTokenPattern string

Regular expression to use for getting a token from authorization header. Token value should match first capturing group.

                public function withHeaderTokenPattern(string $headerTokenPattern): self
{
    $new = clone $this;
    $new->headerTokenPattern = $headerTokenPattern;
    return $new;
}

            
withIdentifier() public method

public self withIdentifier ( string $identifier )
$identifier string

Identifier to check claims for.

                public function withIdentifier(string $identifier): self
{
    $new = clone $this;
    $new->identifier = $identifier;
    return $new;
}

            
withQueryParameterName() public method

public self withQueryParameterName ( string $queryParameterName )
$queryParameterName string

Request parameter name to check for a token.

                public function withQueryParameterName(string $queryParameterName): self
{
    $new = clone $this;
    $new->queryParameterName = $queryParameterName;
    return $new;
}

            
withRealm() public method

public self withRealm ( string $realm )
$realm string

The HTTP authentication realm.

                public function withRealm(string $realm): self
{
    $new = clone $this;
    $new->realm = $realm;
    return $new;
}