<%init>
# It's important to nab the next page from the session before we
# potentially blow the session away below.
my $next = $session{'NextPage'}->{ $ARGS{'next'} || "" };
   $next = $next->{'url'} if ref $next;

my ($val,$msg) = RT::Authen::ExternalAuth::DoAuth(\%session,$user,$pass);
$RT::Logger->debug("Autohandler called ExternalAuth. Response: ($val, $msg)");
if ( $val ) {
    $m->callback( %ARGS, CallbackName => 'SuccessfulLogin', CallbackPage => '/autohandler', RedirectTo => \$next );
}

# Redirect to the relevant page if the above succeeded
RT::Interface::Web::Redirect( $next )
    if $val and $next
   and $m->request_comp->path eq '/NoAuth/Login.html';
</%init>
<%ARGS>
$user => undef
$pass => undef
</%ARGS>

