NAME
Plack::Middleware::OIDC::Redirect - Internal exception class used to signal a redirect
DESCRIPTION
OIDC::Client::Plugin is designed for frameworks where the current request has a mutable response object that a controller can alter at any point ($c-redirect_to(...)> in Mojolicious, for example).
PSGI has no such object: the response is simply the return value of the application coderef. So when application code calls $env-{oidc}->redirect_to_authorize()> or $env-{oidc}->redirect_to_logout()> from deep within its own logic, there is no direct way to make the enclosing PSGI application return early with a redirect response.
To work around this, Plack::Middleware::OIDC gives OIDC::Client::Plugin a redirect coderef that throws an instance of this class instead of performing the redirection itself. Plack::Middleware::OIDC then wraps the call to the downstream application in an eval, catches this exception, and turns it into a real 302 PSGI response.
This mirrors the way Plack::Middleware::HTTPExceptions turns exception objects into HTTP responses, and this class follows the same convention : it implements an "as_psgi()" method, so that it is also understood by the components which look for it.
Frameworks which rethrow the exceptions implementing as_psgi() instead of turning them into an error page will let this exception reach Plack::Middleware::OIDC.
METHODS
new( url => $url )
my $redirect = Plack::Middleware::OIDC::Redirect->new(url => $url);
Creates an exception object to be thrown. The url parameter is the URL the browser must be redirected to.
url()
Returns the URL to redirect to.
my $url = $redirect->url();
as_psgi()
my $psgi_response = $redirect->as_psgi();
Returns the PSGI response (an arrayref [ $status, \@headers, \@body ]) corresponding to this redirection : a 302 status with the Location header set to the "url()".
This method follows the convention used by Plack::Middleware::HTTPExceptions and by the frameworks which look for it : an exception which implements it is considered as "knowing what it wants", and can be handed over to the PSGI layer instead of being handled as an ordinary application error. Plack::Middleware::OIDC calls it to build the response when it catches the exception, and Plack::Middleware::HTTPExceptions would do the same if the exception happened to reach it.