Final Class Yiisoft\Auth\Jwt\JwtMethod
| Inheritance | Yiisoft\Auth\Jwt\JwtMethod |
|---|---|
| Implements | Yiisoft\Auth\AuthenticationMethodInterface |
Authentication method based on JWT token.
Public Methods
Method Details
| public __construct( \Yiisoft\Auth\IdentityRepositoryInterface $identityRepository, Yiisoft\Auth\Jwt\TokenRepositoryInterface $tokenRepository, \Jose\Component\Checker\ClaimChecker[]|null $claimCheckers = null ): mixed | ||
| $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, \Jose\Component\Checker\ExpirationTimeChecker is used. |
public function __construct(
private IdentityRepositoryInterface $identityRepository,
private TokenRepositoryInterface $tokenRepository,
?array $claimCheckers = null,
) {
$this->claimCheckers = $claimCheckers ?? [new ExpirationTimeChecker()];
}
| public authenticate( \Psr\Http\Message\ServerRequestInterface $request ): \Yiisoft\Auth\IdentityInterface|null | ||
| $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]);
}
| public challenge( \Psr\Http\Message\ResponseInterface $response ): \Psr\Http\Message\ResponseInterface | ||
| $response | \Psr\Http\Message\ResponseInterface | |
public function challenge(ResponseInterface $response): ResponseInterface
{
return $response->withHeader(Header::WWW_AUTHENTICATE, "{$this->headerName} realm=\"{$this->realm}\"");
}
| public withHeaderName( string $headerName ): self | ||
| $headerName | string |
Authorization header name. |
public function withHeaderName(string $headerName): self
{
$new = clone $this;
$new->headerName = $headerName;
return $new;
}
| public withHeaderTokenPattern( string $headerTokenPattern ): self | ||
| $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;
}
| public withIdentifier( string $identifier ): self | ||
| $identifier | string |
Identifier to check claims for. |
public function withIdentifier(string $identifier): self
{
$new = clone $this;
$new->identifier = $identifier;
return $new;
}
| public withQueryParameterName( string $queryParameterName ): self | ||
| $queryParameterName | string |
Request parameter name to check for a token. |
public function withQueryParameterName(string $queryParameterName): self
{
$new = clone $this;
$new->queryParameterName = $queryParameterName;
return $new;
}
Signup or Login in order to comment.