Class RedirectHandler
This handler will redirect the response if one of configured exception classes is encountered.
Namespace: Authorization\Middleware\UnauthorizedHandler
Property Summary
-
$defaultOptions protected
arrayDefault config:
Method Summary
-
checkException() protected
Checks if an exception matches one of the classes.
-
getUrl() protected
Returns the url for the Location header.
-
handle() public
Handles the unauthorized request. The modified response should be returned.
-
redirectAllowed() protected
Method Detail
checkException() ¶ protected
checkException(Authorization\Exception\Exception $exception, array<Exception> $exceptions): bool
Checks if an exception matches one of the classes.
Parameters
-
Authorization\Exception\Exception$exception Exception instance.
-
array<Exception>$exceptions A list of exception classes.
Returns
boolgetUrl() ¶ protected
getUrl(Psr\Http\Message\ServerRequestInterface $request, array<string, mixed> $options): string
Returns the url for the Location header.
Parameters
-
Psr\Http\Message\ServerRequestInterface$request Server request.
-
array<string, mixed>$options Options.
Returns
stringhandle() ¶ public
handle(Authorization\Exception\Exception $exception, Psr\Http\Message\ServerRequestInterface $request, array<string, mixed> $options = []): Psr\Http\Message\ResponseInterface
Handles the unauthorized request. The modified response should be returned.
Return a response with a location header set if an exception matches.
Parameters
-
Authorization\Exception\Exception$exception -
Psr\Http\Message\ServerRequestInterface$request -
array<string, mixed>$options optional
Returns
Psr\Http\Message\ResponseInterfaceredirectAllowed() ¶ protected
redirectAllowed(Psr\Http\Message\ServerRequestInterface $request, array $options): bool
Parameters
-
Psr\Http\Message\ServerRequestInterface$request -
array$options
Returns
boolProperty Detail
$defaultOptions ¶ protected
Default config:
exceptions- A list of exception classes.url- Url to redirect to.queryParam- Query parameter name for the target url.statusCode- Redirection status code.allowedRedirectExtensions- If true, redirects are allowed for all extensions. Pass specific ones to allow list, or false to disallow redirects for any extension.
Type
array