Subject: | update plugin to work with Auth > 0.10000 |
Hi miyagawa,
I've updated the plugin to work with the new Auth API, including support
for realms. I tested this in my app, and it's working great... but it
would be nice if someone else could confirm that.
Patch attached.
--
Jonathan Rockway <jrockway@cpan.org>
Subject: | openid_newauth.patch |
Only in Catalyst-Plugin-Authentication-Credential-OpenID-0.03/: blib
diff -ur Catalyst-Plugin-Authentication-Credential-OpenID-0.02/lib/Catalyst/Plugin/Authentication/Credential/OpenID.pm Catalyst-Plugin-Authentication-Credential-OpenID-0.03/lib/Catalyst/Plugin/Authentication/Credential/OpenID.pm
--- Catalyst-Plugin-Authentication-Credential-OpenID-0.02/lib/Catalyst/Plugin/Authentication/Credential/OpenID.pm 2007-05-02 19:05:53.000000000 -0500
+++ Catalyst-Plugin-Authentication-Credential-OpenID-0.03/lib/Catalyst/Plugin/Authentication/Credential/OpenID.pm 2007-08-13 05:32:54.000000000 -0500
@@ -2,25 +2,20 @@
use strict;
use warnings;
-our $VERSION = '0.02';
+our $VERSION = '0.03';
use Net::OpenID::Consumer;
use LWPx::ParanoidAgent;
-use UNIVERSAL::require;
+use Catalyst::Plugin::Authentication::User::Hash;
-sub setup {
- my $c = shift;
- my $config = $c->config->{authentication}->{openid} ||= {};
- ( $config->{user_class}
- ||= "Catalyst::Plugin::Authentication::User::Hash" )->require;
- $c->NEXT::setup(@_);
+sub new {
+ my ($class, $config, $app) = @_;
+ return bless {_config => $config} => $class;
}
-sub authenticate_openid {
- my($c) = @_;
-
- my $config = $c->config->{authentication}->{openid};
-
+sub authenticate {
+ my ($self, $c, $authstore, $authinfo) = @_;
+
my $csr = Net::OpenID::Consumer->new(
ua => LWPx::ParanoidAgent->new,
args => $c->req->params,
@@ -47,21 +42,15 @@
return 0;
} 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;
+ qw( url display rss atom foaf declared_rss
+ declared_atom declared_foaf foafmaker ) };
+
+ # lookup username=<url> or return a new user if none found
+ return $authstore->find_user({username => $identity->url}, $c) ||
+ Catalyst::Plugin::Authentication::User::Hash->new($user);
} else {
Catalyst::Exception->throw("Error validating identity: " .
- $csr->err);
+ $csr->err);
}
} else {
return 0;
@@ -86,23 +75,33 @@
=head1 NAME
-Catalyst::Plugin::Authentication::Credential::OpenID - OpenID credential for Catalyst::Auth framework
+Catalyst::Plugin::Authentication::Credential::OpenID - OpenID
+credential for Catalyst Authentication framework
=head1 SYNOPSIS
use Catalyst qw/
Authentication
- Authentication::Credential::OpenID
- Session
- Session::Store::FastMmap
- Session::State::Cookie
/;
- # MyApp.yaml -- optional
- authentication:
- openid:
- use_session: 1
- user_class: MyApp::M::User::OpenID
+ __PACKAGE__->config->{authentication} =
+ { default_realm => 'openid',
+ realms => {
+ openid => {
+ credential => {
+ class => 'OpenID',
+ },
+ store => {
+ class => 'Minimal',
+ users => {
+ 'http://jrock.us/' => { # username is their OpenID url
+ display => 'Jonathan Rockway',
+ },
+ },
+ }
+ }
+ }
+ };
# whatever in your Controller pm
sub default : Private {
@@ -113,7 +112,7 @@
sub signin_openid : Local {
my($self, $c) = @_;
- if ($c->authenticate_openid) {
+ if ($c->authenticate) {
$c->res->redirect( $c->uri_for('/') );
}
}
@@ -127,19 +126,24 @@
=head1 DESCRIPTION
Catalyst::Plugin::Authentication::Credential::OpenID is an OpenID
-credential for Catalyst::Plugin::Authentication framework.
+credential for Catalyst::Plugin::Authentication framework.
+
+This plugin will pass a C<username> field set to the user's OpenID to
+your store's C<find_user> method. If C<find_user> doesn't return
+anything, a new L<Catalyst::Plugin::Authentication::User::Hash> will
+be returned instead of your store's user object.
=head1 METHODS
=over 4
-=item authenticate_openid
+=item authenticate
- $c->authenticate_openid;
+ $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 1 if user is
-authenticated.
+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
@@ -174,7 +178,9 @@
=head1 DIFFERENCE WITH Authentication::OpenID
There's already Catalyst::Plugin::Authentication::OpenID
-(Auth::OpenID) and this plugin tries to deprecate it.
+(Auth::OpenID) and this plugin tries to deprecate it. It works with
+the new Authentication API, and therefore supports realms and other
+good things.
=over 4
@@ -208,6 +214,8 @@
Six Apart, Ltd. E<lt>cpan@sixapart.comE<gt>
+Jonthan Rockway C<jrockway@cpan.org>
+
=head1 LICENSE
This library is free software; you can redistribute it and/or modify
@@ -215,6 +223,7 @@
=head1 SEE ALSO
-L<Catalyst::Plugin::Authentication::OpenID>, L<Catalyst::Plugin::Authentication::Credential::Flickr>
+L<Catalyst::Plugin::Authentication::OpenID>,
+ L<Catalyst::Plugin::Authentication::Credential::Flickr>
=cut
Only in Catalyst-Plugin-Authentication-Credential-OpenID-0.03/: Makefile
Only in Catalyst-Plugin-Authentication-Credential-OpenID-0.03/: Makefile.old
diff -ur Catalyst-Plugin-Authentication-Credential-OpenID-0.02/Makefile.PL Catalyst-Plugin-Authentication-Credential-OpenID-0.03/Makefile.PL
--- Catalyst-Plugin-Authentication-Credential-OpenID-0.02/Makefile.PL 2006-12-08 02:11:52.000000000 -0600
+++ Catalyst-Plugin-Authentication-Credential-OpenID-0.03/Makefile.PL 2007-08-13 05:33:06.000000000 -0500
@@ -4,7 +4,7 @@
requires 'Net::OpenID::Consumer';
requires 'LWPx::ParanoidAgent';
-requires 'UNIVERSAL::require';
+requires 'Catalyst::Plugin::Authentication' => '0.10002';
build_requires 'Test::More';
use_test_base;
Only in Catalyst-Plugin-Authentication-Credential-OpenID-0.03/: pm_to_blib