Final Class Yiisoft\Auth\Method\HttpBasic
| Inheritance | Yiisoft\Auth\Method\HttpBasic |
|---|---|
| Implements | Yiisoft\Auth\AuthenticationMethodInterface |
HTTP Basic authentication method.
See also https://tools.ietf.org/html/rfc7617 In case authentication does not work as expected, make sure your web server passes username and password
to $request->getServerParams()['PHP_AUTH_USER'] and $request->getServerParams()['PHP_AUTH_PW']
parameters. If you are using Apache with PHP-CGI, you might need to add this line to your .htaccess file:
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L].
Public Methods
Method Details
| public mixed __construct ( Yiisoft\Auth\IdentityWithTokenRepositoryInterface $identityRepository ) | ||
| $identityRepository | Yiisoft\Auth\IdentityWithTokenRepositoryInterface | |
public function __construct(private IdentityWithTokenRepositoryInterface $identityRepository)
{
}
| public Yiisoft\Auth\IdentityInterface|null authenticate ( \Psr\Http\Message\ServerRequestInterface $request ) | ||
| $request | \Psr\Http\Message\ServerRequestInterface | |
public function authenticate(ServerRequestInterface $request): ?IdentityInterface
{
[$username, $password] = $this->getAuthenticationCredentials($request);
if ($this->authenticationCallback !== null && ($username !== null || $password !== null)) {
return call_user_func($this->authenticationCallback, $username, $password, $this->identityRepository);
}
if ($username !== null) {
return $this->identityRepository->findIdentityByToken($username, $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, "Basic realm=\"{$this->realm}\"");
}
| public self withAuthenticationCallback ( callable $authenticationCallback ) | ||
| $authenticationCallback | callable |
A PHP callable that will authenticate the user with the HTTP basic authentication information. The callable should have the following signature:
It should return an identity object that matches the username and password. Null should be returned if there is no such identity. The callable will be called only if current user is not authenticated. If not set, the username information will be considered as an access token while the password information will be ignored. The {@see \Yiisoft\Auth\IdentityWithTokenRepositoryInterface::findIdentityByToken()} method will be called to authenticate an identity. |
public function withAuthenticationCallback(callable $authenticationCallback): self
{
$new = clone $this;
$new->authenticationCallback = $authenticationCallback;
return $new;
}
| public $this withRealm ( string $realm ) | ||
| $realm | string |
The HTTP authentication realm. |
public function withRealm(string $realm): self
{
$new = clone $this;
$new->realm = $realm;
return $new;
}
Signup or Login in order to comment.