Final Class Yiisoft\Auth\Method\HttpBearer
| Inheritance | Yiisoft\Auth\Method\HttpBearer » Yiisoft\Auth\Method\HttpHeader |
|---|---|
| Implements | Yiisoft\Auth\AuthenticationMethodInterface |
Authentication method based on HTTP Bearer token.
See also https://tools.ietf.org/html/rfc6750.
Protected Properties
Public Methods
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| getAuthenticationToken() | Yiisoft\Auth\Method\HttpHeader |
Property Details
Method Details
Defined in: Yiisoft\Auth\Method\HttpHeader::__construct()
| public __construct( Yiisoft\Auth\IdentityWithTokenRepositoryInterface $identityRepository ): mixed | ||
| $identityRepository | Yiisoft\Auth\IdentityWithTokenRepositoryInterface | |
public function __construct(protected IdentityWithTokenRepositoryInterface $identityRepository) {}
Defined in: Yiisoft\Auth\Method\HttpHeader::authenticate()
| public authenticate( \Psr\Http\Message\ServerRequestInterface $request ): Yiisoft\Auth\IdentityInterface|null | ||
| $request | \Psr\Http\Message\ServerRequestInterface | |
public function authenticate(ServerRequestInterface $request): ?IdentityInterface
{
$authToken = $this->getAuthenticationToken($request);
if ($authToken !== null) {
return $this->identityRepository->findIdentityByToken($authToken, $this->tokenType);
}
return null;
}
| 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}\"");
}
| protected getAuthenticationToken( \Psr\Http\Message\ServerRequestInterface $request ): string|null | ||
| $request | \Psr\Http\Message\ServerRequestInterface | |
protected function getAuthenticationToken(ServerRequestInterface $request): ?string
{
$authHeaders = $request->getHeader($this->headerName);
$authHeader = reset($authHeaders);
if (!empty($authHeader)) {
if (preg_match($this->pattern, $authHeader, $matches)) {
$authHeader = $matches[1];
} else {
return null;
}
return $authHeader;
}
return null;
}
Defined in: Yiisoft\Auth\Method\HttpHeader::withHeaderName()
| public withHeaderName( string $name ): $this | ||
| $name | string |
The HTTP header name. |
public function withHeaderName(string $name): self
{
$new = clone $this;
$new->headerName = $name;
return $new;
}
Defined in: Yiisoft\Auth\Method\HttpHeader::withPattern()
| public withPattern( string $pattern ): self | ||
| $pattern | string |
A pattern to use to extract the HTTP authentication value. |
public function withPattern(#[Language('RegExp')] string $pattern): self
{
$new = clone $this;
$new->pattern = $pattern;
return $new;
}
| public withRealm( string $realm ): self | ||
| $realm | string |
The HTTP authentication realm. |
public function withRealm(string $realm): self
{
$new = clone $this;
$new->realm = $realm;
return $new;
}
Defined in: Yiisoft\Auth\Method\HttpHeader::withTokenType()
| public withTokenType( string|null $type ): $this | ||
| $type | string|null |
Identity token type |
public function withTokenType(?string $type): self
{
$new = clone $this;
$new->tokenType = $type;
return $new;
}
Signup or Login in order to comment.