Catalyst::Authentication::Credential::RPX - Use JanRain's RPX service for Credentials


Catalyst-Authentication-Credential-RPX documentation Contained in the Catalyst-Authentication-Credential-RPX distribution.

Index


Code Index:

NAME

Top

Catalyst::Authentication::Credential::RPX - Use JanRain's RPX service for Credentials

VERSION

Top

version 0.10053905

SYNOPSIS

Top

    use Catalyst qw/ Authentication /;

    package MyApp::Controller::Auth;

    sub login : Local {
        my ( $self , $c ) = @_;
        $c->authenticate();
    }

CONFIGURATION

Top

    __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',
          }
        }
      }
    });

ATTRIBUTES

Top

api_key Str[ro]*

The API Key for connecting to the RPX server.

base_url Str[ro]

The URL The RPX server interconnects with.

ua Str[ro]

The User-Agent String.

token_field Str[ro] = 'token'

The token to look for in request parameters

last_auth_info HashRef[rw]X

The results of the last call to ->auth_info

AUTHENTICATION METHODS

Top

authenticate

authenticate ( $context, $realm, $authinfo )

    ->authenticate( $context, $realm, $authinfo )

authenticate_rpx

authenticate_rpx ( @args )

    ->authenticate_rpx( @args )

CONSTRUCTOR METHODS

Top

new

new ( $config, $app, $realm );

This method is called by the Authentication API.

    ->new( $config , $app , $realm );

ATTRIBUTE METHODS

Top

has_base_url <- predicate('base_url')

has_ua <- predicate('ua')

has_last_auth_info <- predicate('last_auth_info')

clear_last_auth_info <- clearer('last_auth_info')

auth_info <- _api_driver

map <- _api_driver

unmap <- _api_driver

mappings <- _api_driver

PRIVATE ATTRIBUTES

Top

_config HashRef[rw]*

_app Object|ClassName [rw]*

_realm Object[rw]*

_api_driver Object[ro]

PRIVATE BUILDERS

Top

_build__api_driver

Creates an instance of Net::API::RPX|Net::API::RPX for us to communicate with.

    ->_build__api_driver

AUTHOR

Top

Kent Fredric <kentnl@cpan.org>

COPYRIGHT AND LICENSE

Top


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__