Authen-CAS-External
view release on metacpan or search on metacpan
lib/Authen/CAS/External/UserAgent.pm view on Meta::CPAN
last TOKEN;
}
}
# Return the notification
return $notification;
}
sub _extract_service_redirect_link {
my ($response) = @_;
# For the service redirect to be populated into
my $service_redirect;
# Prase the document using HTML::TokeParser
my $parser = HTML::TokeParser->new($response->content_ref);
# Cycle through the tokens on the page
TOKEN: while (my $token = $parser->get_token) {
# Move to the next token if this is not a start tag
next TOKEN
if $token->[0] ne q{S};
# Get the tag of this start tag
my $tag = lc $token->[1];
if ($tag eq q{a}) {
# This is the start of an anchor tag. Anchor tags need to be
# scanned for the service redirect.
if (exists $token->[2]->{href} && $token->[2]->{href} =~ m{ticket=ST-}msx) {
# This is the service redirect link.
# Set the service redirect link from this link
$service_redirect = URI->new($token->[2]->{href});
# End the parsing
last TOKEN;
}
}
}
# Return the service redirect
return $service_redirect;
}
sub _process_login_page {
my ($response, $user_agent, $info) = @_;
my $self = ${$info->{object_instance}};
if ($response->request->method eq 'POST') {
if (!$self->has_previous_response) {
# A POST returning to the login page is a failure
confess 'The login failed with the supplied credentials';
}
# The previous response can determine what occurred
return;
}
# Parse the forms on the page
my @forms = HTML::Form->parse($response->decoded_content, $response->base);
# Find the login form
my $login_form;
FORM: foreach my $form (@forms) {
if (defined $form->find_input('lt')
&& defined $form->find_input('username')
&& defined $form->find_input('password')) {
# Set this as the login form
$login_form = $form;
# Do not continue to search the forms
last FORM;
}
}
if (!defined $login_form) {
confess 'The login form could not be identified on the login page';
}
# The service this form is for
my $service = $login_form->param('service');
# Get the username and password
my ($username, $password) = $self->get_cas_credentials($service);
# Fill in the form
$login_form->param(username => $username);
$login_form->param(password => $password);
# Get the request to make
my $request = $login_form->make_request;
return $request;
}
sub _process_ticket_granting_cookie {
my ($request, $user_agent, $info) = @_;
my $self = ${$info->{object_instance}};
# Clear previous response
$self->clear_previous_response;
# Get the service
my $service = $request->uri->query_param('service');
if (defined $user_agent->cookie_jar) {
# Clear all CAS cookies
$user_agent->cookie_jar->clear($self->cas_url->host);
# Get the CAS credentials
my ($username, $password) = $self->get_cas_credentials($service);
# Get the ticket granting ticket
my $ticket_granting_cookie = $self->get_cas_ticket_granting_cookie(
$username,
$service
);
if (defined $ticket_granting_cookie) {
# Set the cookie for the upcoming request
( run in 1.794 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )