Authen-CAS-External
view release on metacpan or search on metacpan
lib/Authen/CAS/External.pm view on Meta::CPAN
package Authen::CAS::External;
use 5.008001;
use strict;
use utf8;
use warnings 'all';
# Module metadata
our $AUTHORITY = 'cpan:DOUGDUDE';
our $VERSION = '0.08';
use Authen::CAS::External::Library qw(TicketGrantingCookie);
use Moose 0.89;
use MooseX::StrictConstructor 0.08;
use MooseX::Types::Moose qw(Str);
use URI 1.22;
# Clean the imports are the end of scope
use namespace::clean 0.04 -except => [qw(meta)];
# Role
with 'Authen::CAS::External::UserAgent';
# Attributes
has password => (
is => 'rw',
isa => Str,
clearer => 'clear_password',
predicate => 'has_password',
trigger => sub { shift->clear_ticket_granting_cookie },
);
has ticket_granting_cookie => (
is => 'rw',
isa => TicketGrantingCookie,
clearer => 'clear_ticket_granting_cookie',
documentation => q{The Ticket Granting Cookie for the CAS user session},
predicate => 'has_ticket_granting_cookie',
);
has username => (
is => 'rw',
isa => Str,
clearer => 'clear_username',
predicate => 'has_username',
trigger => sub { shift->clear_ticket_granting_cookie },
);
# Methods
sub authenticate {
my ($self, %args) = @_;
# Splice out the variables
my ($service, $gateway, $renew) = @args{qw(service gateway renew)};
# Get the URI to request
my $url = $self->service_request_url(
(defined $gateway ? (gateway => $gateway) : () ),
(defined $renew ? (renew => $renew ) : () ),
(defined $service ? (service => $service) : () ),
);
# Do not redirect back to service
my $redirect_back = $self->redirect_back;
$self->redirect_back(0);
# Get the service
my $response = $self->get($url);
# Restore previous value
$self->redirect_back($redirect_back);
if (!$self->has_previous_response) {
confess 'Failed retrieving response';
}
# 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';
( run in 0.555 second using v1.01-cache-2.11-cpan-39bf76dae61 )