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 mixed __construct ( Yiisoft\Auth\IdentityWithTokenRepositoryInterface $identityRepository ) | ||
| $identityRepository | Yiisoft\Auth\IdentityWithTokenRepositoryInterface | |
public function __construct(protected IdentityWithTokenRepositoryInterface $identityRepository)
{
}
Defined in: Yiisoft\Auth\Method\HttpHeader::authenticate()
| public Yiisoft\Auth\IdentityInterface|null authenticate ( \Psr\Http\Message\ServerRequestInterface $request ) | ||
| $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 \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}\"");
}
| protected string|null getAuthenticationToken ( \Psr\Http\Message\ServerRequestInterface $request ) | ||
| $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 $this withHeaderName ( string $name ) | ||
| $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 self withPattern ( string $pattern ) | ||
| $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 self withRealm ( string $realm ) | ||
| $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 $this withTokenType ( string|null $type ) | ||
| $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.