Final Class Yiisoft\Auth\Middleware\Authentication
| Inheritance | Yiisoft\Auth\Middleware\Authentication |
|---|---|
| Implements | Psr\Http\Server\MiddlewareInterface |
Authentication middleware tries to authenticate and identity using request data.
If identity is found, it is set to request attribute allowing further middleware to obtain and use it. If identity is not found failure handler is called. By default it is Yiisoft\Auth\Handler\AuthenticationFailureHandler.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Auth\Middleware\Authentication | |
| process() | Yiisoft\Auth\Middleware\Authentication | |
| withOptionalPatterns() | Yiisoft\Auth\Middleware\Authentication |
Method Details
| public __construct( Yiisoft\Auth\AuthenticationMethodInterface $authenticationMethod, \Psr\Http\Message\ResponseFactoryInterface $responseFactory, \Psr\Http\Server\RequestHandlerInterface|null $authenticationFailureHandler = null ): mixed | ||
| $authenticationMethod | Yiisoft\Auth\AuthenticationMethodInterface | |
| $responseFactory | \Psr\Http\Message\ResponseFactoryInterface | |
| $authenticationFailureHandler | \Psr\Http\Server\RequestHandlerInterface|null | |
public function __construct(
private AuthenticationMethodInterface $authenticationMethod,
ResponseFactoryInterface $responseFactory,
?RequestHandlerInterface $authenticationFailureHandler = null,
) {
$this->failureHandler = $authenticationFailureHandler ?? new AuthenticationFailureHandler(
$responseFactory,
);
}
| public process( \Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Server\RequestHandlerInterface $handler ): \Psr\Http\Message\ResponseInterface | ||
| $request | \Psr\Http\Message\ServerRequestInterface | |
| $handler | \Psr\Http\Server\RequestHandlerInterface | |
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$identity = $this->authenticationMethod->authenticate($request);
$request = $request->withAttribute(self::class, $identity);
if ($identity === null && !$this->isOptional($request)) {
return $this->authenticationMethod->challenge(
$this->failureHandler->handle($request),
);
}
return $handler->handle($request);
}
See also \Yiisoft\Strings\WildcardPattern.
| public withOptionalPatterns( array $optional ): self | ||
| $optional | array |
Patterns to match to consider the given request URI path optional. |
public function withOptionalPatterns(array $optional): self
{
$new = clone $this;
$new->optionalPatterns = $optional;
return $new;
}
Signup or Login in order to comment.