Authen-CAS-External
view release on metacpan or search on metacpan
lib/Authen/CAS/External.pm view on Meta::CPAN
# Set our ticket granting ticket if we have one
if ($self->previous_response->has_ticket_granting_cookie) {
$self->ticket_granting_cookie($self->previous_response->ticket_granting_cookie);
}
# Return the last response
return $self->previous_response;
}
sub get_cas_credentials {
my ($self, $service) = @_;
# This default callback stub simply returns the stored
# credentials
if (!$self->has_username) {
confess 'Unable to authenticate because no username was provided';
}
if (!$self->has_password) {
confess 'Unable to authenticate because no password was provided';
}
# Return username, password
return $self->username, $self->password;
}
sub get_cas_ticket_granting_cookie {
my ($self, %args) = @_;
# Splice out the variables
my ($username, $service) = @args{qw(username service)};
# This default callback stub simply returns the stored
# credentials
if (!$self->has_ticket_granting_cookie) {
return;
}
# Return ticket granting ticket
return $self->ticket_granting_cookie;
}
# Make immutable
__PACKAGE__->meta->make_immutable;
lib/Authen/CAS/External.pm view on Meta::CPAN
This is a Boolean of if the renew parameter should be sent to the CAS server.
The default is to not send any renew parameter.
=item service
This is a string that specifies the service value to send to the CAS server.
The default is to not send any service parameter.
=back
=head2 get_cas_credentials
This method is not actually used, but is required for classes to consume the
L<Authen::CAS::External::UserAgent|Authen::CAS::External::UserAgent> role as
this class does. This method will return the currently set username and
password to the user agent.
=head2 get_cas_ticket_granting_cookie
This method is not actually used but is required for classes to consume the
L<Authen::CAS::External::UserAgent|Authen::CAS::External::UserAgent> role as
lib/Authen/CAS/External/UserAgent.pm view on Meta::CPAN
use Scalar::Util 1.14;
use URI 1.22;
use URI::QueryParam;
# Clean the imports are the end of scope
use namespace::clean 0.04 -except => [qw(meta)];
# Role requires
requires qw(
get_cas_credentials
get_cas_ticket_granting_cookie
);
# Attributes
has previous_response => (
is => 'rw',
isa => 'Authen::CAS::External::Response',
clearer => 'clear_previous_response',
lib/Authen/CAS/External/UserAgent.pm view on Meta::CPAN
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
lib/Authen/CAS/External/UserAgent.pm view on Meta::CPAN
}
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;
}
lib/Authen/CAS/External/UserAgent.pm view on Meta::CPAN
# 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
$user_agent->cookie_jar->set_cookie(
lib/Authen/CAS/External/UserAgent.pm view on Meta::CPAN
=head1 SYNOPSIS
package MyCAS::Session;
use Moose;
# Use this role
with 'Authen::CAS::External::UserAgent';
sub get_cas_credentials {
my ($self, $service) = @_;
# Do something
return $username, $password;
}
sub get_cas_ticket_granting_cookie {
my ($self, $username, $service) = @_;
lib/Authen/CAS/External/UserAgent.pm view on Meta::CPAN
Provides a way to authenticate with a CAS server just as a browser
would. This is useful with web scrapers needing to login to a CAS
site.
=head1 ROLE REQUIRES
This is a L<Moose::Role|Moose::Role> and for this role to be used, the user
MUST provide the following two methods:
=head2 get_cas_credentials
This is called as a method with the first argument being a string that is the
URL of the service that is about to be logged in to. If no service is being
logged in to, then it will be undefined. This function is expected to return
a username string and a password string, both of which are optional, but MUST
be returned in that order.
=head2 get_cas_ticket_granting_cookie
This is called as a method with the first argument being a string that is the
( run in 0.929 second using v1.01-cache-2.11-cpan-4d50c553e7e )