0 follower

Final Class Yiisoft\User\Method\WebAuth

InheritanceYiisoft\User\Method\WebAuth
ImplementsYiisoft\Auth\AuthenticationMethodInterface

Implementation of the AuthenticationMethodInterface for authenticating users in the web applications.

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( Yiisoft\User\CurrentUser $currentUser, \Psr\Http\Message\ResponseFactoryInterface $responseFactory )
$currentUser Yiisoft\User\CurrentUser
$responseFactory \Psr\Http\Message\ResponseFactoryInterface

                public function __construct(
    private readonly CurrentUser $currentUser,
    private readonly ResponseFactoryInterface $responseFactory
) {
}

            
authenticate() public method

public \Yiisoft\Auth\IdentityInterface|null authenticate ( \Psr\Http\Message\ServerRequestInterface $request )
$request \Psr\Http\Message\ServerRequestInterface

                public function authenticate(ServerRequestInterface $request): ?IdentityInterface
{
    if ($this->currentUser->isGuest()) {
        return null;
    }
    return $this->currentUser->getIdentity();
}

            
challenge() public method

Creates a new instance of the response and adds a Location header with a temporary redirect.

public challenge ( \Psr\Http\Message\ResponseInterface $response )
$response \Psr\Http\Message\ResponseInterface

                public function challenge(ResponseInterface $response): ResponseInterface
{
    return $this->responseFactory
        ->createResponse(Status::FOUND)
        ->withHeader('Location', $this->authUrl);
}

            
withAuthUrl() public method

Returns a new instance with the specified authentication URL.

public self withAuthUrl ( string $url )
$url string

The authentication URL.

                public function withAuthUrl(string $url): self
{
    $new = clone $this;
    $new->authUrl = $url;
    return $new;
}