Skip Menu |

This queue is for tickets about the Catalyst-Plugin-Authentication-Credential-OpenID CPAN distribution.

Report information
The Basics
Id: 30659
Status: new
Priority: 0/
Queue: Catalyst-Plugin-Authentication-Credential-OpenID

People
Owner: Nobody in particular
Requestors: masaki [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.03
Fixed in: (no value)



Subject: [PATCH] Can't work with new Auth API
Hi. I wrote a patch for Catalyst::Plugin::Authentication::Credential::OpenID version 0.03 to work with new Authenticaion API (>= 0.10), and it also works with old API (< 0.10). Patch is attached.
Subject: openid_newauth.patch
--- /usr/lib/perl5/site_perl/5.8.8/Catalyst/Plugin/Authentication/Credential/OpenID.pm 2007-10-27 05:27:23.000000000 +0900 +++ lib/Catalyst/Plugin/Authentication/Credential/OpenID.pm 2007-11-06 19:08:08.000000000 +0900 @@ -2,12 +2,19 @@ use strict; use warnings; -our $VERSION = '0.03'; +our $VERSION = '0.03_01'; use Net::OpenID::Consumer; use LWPx::ParanoidAgent; use UNIVERSAL::require; +sub new { + my($class, $config, $c) = @_; + ( $config->{user_class} + ||= "Catalyst::Plugin::Authentication::User::Hash" )->require; + return bless { config => $config } => $class; +} + sub setup { my $c = shift; my $config = $c->config->{authentication}->{openid} ||= {}; @@ -16,11 +23,38 @@ $c->NEXT::setup(@_); } +sub authenticate { + my($self, $c, $authstore, $authinfo) = @_; + + my $user = _authenticate_openid($c, $authinfo->{username}) or return; + + $user->{username} = $user->{url}; + return $authstore->find_user($user, $c) + || $self->config->{user_class}->new($user); +} + sub authenticate_openid { my($c, $uri) = @_; + my $user = _authenticate_openid($c, $uri) or return; + my $config = $c->config->{authentication}->{openid}; + my $store = $config->{store} || $c->default_auth_store; + if ( $store + and my $store_user + = $store->get_user( $user->{url}, $user ) ) { + $c->set_authenticated($store_user); + } else { + $user = $config->{user_class}->new($user); + $c->set_authenticated($user); + } + return 1; +} + +sub _authenticate_openid { + my($c, $uri) = @_; + my $csr = Net::OpenID::Consumer->new( ua => LWPx::ParanoidAgent->new, args => $c->req->params, @@ -49,17 +83,7 @@ } elsif (my $identity = $csr->verified_identity) { my $user = +{ map { $_ => scalar $identity->$_ } qw( url display rss atom foaf declared_rss declared_atom declared_foaf foafmaker ) }; - - my $store = $config->{store} || $c->default_auth_store; - if ( $store - and my $store_user - = $store->get_user( $user->{url}, $user ) ) { - $c->set_authenticated($store_user); - } else { - $user = $config->{user_class}->new($user); - $c->set_authenticated($user); - } - return 1; + return $user; } else { Catalyst::Exception->throw("Error validating identity: " . $csr->err); @@ -126,6 +150,37 @@ <input type="submit" value="Sign in with OpenID" /> </form> +NEW AUTHENTICATION API (Catalyst::Plugin::Authentication 0.10) + + use Catalyst qw/ + Authentication + /; + + # MyApp.ym + authentication: + default_realm: openid + realms: + openid: + credential: + class: OpenID + store: + class: Minimal + users: {} + + # whatever in your Controller pm + sub default : Private { + my($self, $c) = @_; + if ($c->user_exists) { ... } + } + + sub signin_openid : Local { + my($self, $c) = @_; + + if ($c->authenticate) { + $c->res->redirect( $c->uri_for('/') ); + } + } + =head1 DESCRIPTION Catalyst::Plugin::Authentication::Credential::OpenID is an OpenID @@ -180,6 +235,35 @@ =back +=head2 NEW AUTHENTICATION API + +=over 4 + +=item new + +Call internally. + +=item authenticate + + $c->authenticate; + +Call this method in the action you'd like to authenticate the user via +OpenID. Returns 0 if auth is not successful, and the user object if +user is authenticated. + +User class specified with I<user_class> config, which defaults to +Catalyst::Plugin::Authentication::User::Hash, will be instantiated +with the following parameters. + +By default, L<authenticate> method looks for claimed URI +parameter from the form field named C<openid_url>, +C<openid_identifier> or C<claimed_uri>. If you want to use another +form field name, call it like: + + $c->authenticate({ username => $c->req->param('myopenid_param') }); + +=back + =head1 DIFFERENCE WITH Authentication::OpenID There's already Catalyst::Plugin::Authentication::OpenID