Authen-CAS-UserAgent
view release on metacpan or search on metacpan
lib/Authen/CAS/UserAgent.pm view on Meta::CPAN
my $ticketResponse = $ua->simple_request(HTTP::Request::Common::POST($tgtUri, [
'service' => $service,
]));
return if($ticketResponse->code != 200);
return $ticketResponse->decoded_content;
};
##Static Methods
#return the default user agent for this class
sub _agent($) {
return
$_[0]->SUPER::_agent . ' ' .
'CAS-UserAgent/' . $VERSION;
}
#Constructor
sub new($%) {
my $self = shift;
my (%opt) = @_;
# remove any cas options before creating base object
my $cas_opts = delete $opt{'cas_opts'};
#setup the base object
$self = $self->SUPER::new(%opt);
#attach a cas login handler if options were specified
lib/Authen/CAS/UserAgent.pm view on Meta::CPAN
#method that will attach the cas server login handler
# server => the base CAS server uri to add a login handler for
# username => the username to use to login to the specified CAS server
# password => the password to use to login to the specified CAS server
# pgt => the pgt for a proxy login handler
# proxy => a boolean indicating this handler is a proxy login handler
# restful => a boolean indicating if the CAS server supports the RESTful API
# callback => a login callback to use for logging into CAS, it should return a ticket for the specified service
# ticket_heuristics => an array of heuristic callbacks that are performed when searching for the service and ticket in a CAS response
# strict => only allow CAS login when the service is the same as the original url
sub attach_cas_handler($%) {
my $self = shift;
my (%opt) = @_;
#short-circuit if required options aren't specified
return if(!exists $opt{'server'});
return if(!$opt{'proxy'} && !(exists $opt{'username'} && exists $opt{'password'}));
return if($opt{'proxy'} && !$opt{'pgt'});
#sanitize options
$opt{'server'} = URI->new($opt{'server'} . ($opt{'server'} =~ /\/$/o ? '' : '/'))->canonical;
lib/Authen/CAS/UserAgent.pm view on Meta::CPAN
HTTP::Status::HTTP_MOVED_PERMANENTLY,
HTTP::Status::HTTP_FOUND,
HTTP::Status::HTTP_SEE_OTHER,
HTTP::Status::HTTP_TEMPORARY_REDIRECT,
],
);
return 1;
}
sub get_cas_handlers($;$) {
my $self = shift;
my ($server) = @_;
$server = URI->new($server . ($server =~ /\/$/o ? '' : '/'))->canonical if(defined $server);
return $self->get_my_handler('response_done',
'owner' => CASHANDLERNAME,
(defined $server ? ('casServer' => $server) : ()),
);
}
# method that will retrieve a ticket for the specified service
sub get_cas_ticket($$;$) {
my $self = shift;
my ($service, $server) = @_;
# resolve which handler to use
my $h;
if(ref($server) eq 'HASH' && defined $server->{'casServer'}) {
$h = $server;
}
else {
my @handlers = $self->get_cas_handlers($server);
lib/Authen/CAS/UserAgent.pm view on Meta::CPAN
# get a ticket from the handler
$h->{'running'}++;
my $ticket = eval {$h->{'loginCb'}->($service, LWP::UserAgent->new('cookie_jar' => {}), $h)};
$h->{'running'}--;
# return the found ticket
return $ticket;
}
#method that will remove the cas login handlers for the specified cas servers or all if a specified server is not provided
sub remove_cas_handlers($@) {
my $self = shift;
#remove cas login handlers for any specified cas servers
$self->remove_handler('response_done',
'owner' => CASHANDLERNAME,
'casServer' => $_,
) foreach(map {URI->new($_ . ($_ =~ /\/$/o ? '' : '/'))->canonical} @_);
#remove all cas login handlers if no servers were specified
$self->remove_handler('response_done',
( run in 0.611 second using v1.01-cache-2.11-cpan-65fba6d93b7 )