Force autoRedirect even with portal errors
I have a use case where I do not want to use the portal web interface, but POST credentials from antoher application to the portal.
Of course, we will also send the "url" parameter to be redirect in case of success. But I would like to be redirect even in case of error, with the error code added in return URL.
Here is a little patch:
===================================================================
--- trunk/modules/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Simple.pm (révision 1327)
+++ trunk/modules/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Simple.pm (copie de travail)
@@ -883,6 +883,35 @@
issuerForAuthUser autoRedirect)
);
$self->updateStatus;
+
+ # forceAutoRedirect: never display portal even with errors
+ if ( $self->{forceAutoRedirect}
+ and ( $self->{urldc} or $self->{error} == PE_BADURL ) )
+ {
+
+ # If URL was bad, use referer
+ $self->{urldc} ||= $self->referer();
+
+ # Add error code in URL
+ if ( $self->{urldc} !~ /sso_error=/ ) {
+ if ( $self->{urldc} =~ /\Q?\E/ ) { $self->{urldc} .= "&"; }
+ else { $self->{urldc} .= "?"; }
+ $self->{urldc} .= "sso_error=" . $self->{error};
+ }
+ else {
+ $self->{urldc} =~ s/sso_error=(\d+)/sso_error=$self->{error}/;
+ }
+
+ # Redirect
+ $self->lmLog( "Force redirection on " . $self->{urldc}, 'debug' );
+ $self->SUPER::redirect(
+ -uri => $self->{urldc},
+ -status => '303 See Other'
+ );
+ $self->quit();
+ }
+
+ # Return result
return ( ( $self->{error} > 0 ) ? 0 : 1 );
}