| Catalyst-Authentication-Credential-RPX documentation | Contained in the Catalyst-Authentication-Credential-RPX distribution. |
Catalyst::Authentication::Credential::RPX - Use JanRain's RPX service for Credentials
version 0.10053905
use Catalyst qw/ Authentication /;
package MyApp::Controller::Auth;
sub login : Local {
my ( $self , $c ) = @_;
$c->authenticate();
}
__PACKAGE__->config('Plugin::Authentication' => {
default_realm => 'RPX_Service',
realms => {
RPX_Service => {
credential => {
class => 'RPX',
# Package Options
api_key => 'ASDF...',
# optional fields
base_url => 'http://foo.bar.org',
ua => 'Firefox',
token_field => 'token',
}
}
}
});
The API Key for connecting to the RPX server.
The URL The RPX server interconnects with.
The User-Agent String.
The token to look for in request parameters
The results of the last call to ->auth_info
->authenticate( $context, $realm, $authinfo )
->authenticate_rpx( @args )
This method is called by the Authentication API.
->new( $config , $app , $realm );
unmap <- _api_driverCreates an instance of Net::API::RPX|Net::API::RPX for us to communicate with.
->_build__api_driver
Kent Fredric <kentnl@cpan.org>
This software is Copyright (c) 2011 by 'Cloudtone Studios'.
This is free software, licensed under:
The (three-clause) BSD License
| Catalyst-Authentication-Credential-RPX documentation | Contained in the Catalyst-Authentication-Credential-RPX distribution. |
use strict; use warnings; package Catalyst::Authentication::Credential::RPX; BEGIN { $Catalyst::Authentication::Credential::RPX::VERSION = '0.10053905'; } # ABSTRACT: Use JanRain's RPX service for Credentials use Moose; use MooseX::Types::Moose qw( :all ); use MooseX::Has::Sugar; use namespace::autoclean; use Net::API::RPX; has 'api_key' => ( isa => Str, ro, required, ); has 'base_url' => ( isa => Str, ro, predicate => 'has_base_url', ); has 'ua' => ( isa => Str, ro, predicate => 'has_ua', ); has 'token_field' => ( isa => Str, ro, default => 'token' ); has 'last_auth_info' => ( rw, isa => HashRef, init_arg => undef, predicate => 'has_last_auth_info', clearer => 'clear_last_auth_info', ); has '_config' => ( isa => HashRef, rw, required, ); has '_app' => ( isa => Object | ClassName, rw, required, ); has '_realm' => ( isa => Object, rw, required, ); has '_api_driver' => ( lazy_build, ro, isa => Object, init_arg => undef, handles => [qw( auth_info map unmap mappings )], ); sub BUILDARGS { my ( $class, @arg_list ) = @_; ## no critic (ProhibitMagicNumbers) if ( @arg_list == 3 ) { my %args = ( _config => $arg_list[0], _app => $arg_list[1], _realm => $arg_list[2], ); for ( keys %{ $args{'_config'} } ) { $args{$_} = $args{'_config'}->{$_}; } return $class->SUPER::BUILDARGS(%args); } return $class->SUPER::BUILDARGS(@arg_list); } sub _build__api_driver { my $self = shift; my $conf = { api_key => $self->api_key }; if ( $self->has_base_url ) { $conf->{'base_url'} = $self->base_url; } if ( $self->has_ua ) { $conf->{'ua'} = $self->ua; } return Net::API::RPX->new($conf); } sub authenticate { my ( $self, $c, $realm, $authinfo ) = @_; my $token_field = $self->token_field; my $token; unless ( exists $c->req->params->{$token_field} ) { return; } $token = $c->req->params->{$token_field}; my $result = $self->authenticate_rpx( { token => $token } ); if ( exists $result->{'err'} ) { return; } my $user_obj = $realm->find_user($result, $c); if(ref $user_obj) { return $user_obj; } return; } sub authenticate_rpx { my ( $self, @args ) = @_; $self->clear_last_auth_info if $self->has_last_auth_info; my $result = $self->_api_driver->auth_info(@args); $self->last_auth_info($result); return $result; } no Moose; __PACKAGE__->meta->make_immutable; 1; __END__