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 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()];
}
| 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]);
}
| 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}\"");
}
| public self withHeaderName ( string $headerName ) | ||
| $headerName | string |
Authorization header name. |
public function withHeaderName(string $headerName): self
{
$new = clone $this;
$new->headerName = $headerName;
return $new;
}
| 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;
}
| 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;
}
| 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;
}
Signup or Login in order to comment.