X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FPlugin%2FAuthentication%2FCredential%2FTypeKey.pm;fp=lib%2FCatalyst%2FPlugin%2FAuthentication%2FCredential%2FTypeKey.pm;h=4d9df06f0807e9556653eac1e68a8eb0f38ca7e1;hb=e0a35f10bc9cf9d138afe1de9aa5a7ba3e4b158c;hp=9165678e0d2b2350b474bf83e75f76674c2b50da;hpb=c38534fd98a2fd0cef0d8f0586affebb50e9d036;p=catagits%2FCatalyst-Authentication-Credential-HTTP-Proxy.git diff --git a/lib/Catalyst/Plugin/Authentication/Credential/TypeKey.pm b/lib/Catalyst/Plugin/Authentication/Credential/TypeKey.pm index 9165678..4d9df06 100644 --- a/lib/Catalyst/Plugin/Authentication/Credential/TypeKey.pm +++ b/lib/Catalyst/Plugin/Authentication/Credential/TypeKey.pm @@ -27,7 +27,7 @@ sub setup { my $typekey = Authen::TypeKey->new; - for (grep { exists $config->{$_} } qw/expires key_cache key_url token version/) { + for (grep { exists $config->{$_} } qw/expires key_cache key_url token version skip_expiry_check/) { $typekey->$_( $config->{$_} ); } @@ -38,33 +38,30 @@ sub setup { } sub authenticate_typekey { - my ( $c, %parameters ) = @_; + my ( $c, @p ) = @_; + my $p = @p ? { @p } : undef; my $config = $c->config->{authentication}{typekey}; - my $typekey = delete( $parameters{typekey_object} ) + my $typekey = $p && delete( $p->{typekey_object} ) || $config->{typekey_object}; - my @fields = qw/email name nick ts sig/; - - foreach my $field (@fields) { - $parameters{$field} ||= $c->req->param($field) || return; - } - - if ( $typekey->verify( \%parameters ) ) { - $c->log->debug("Successfully authenticated user '$parameters{name}'.") + $p ||= $c->req; + + if ( my $res = $typekey->verify( $p ) ) { + $c->log->debug("Successfully authenticated user '$res->{name}'.") if $c->debug; my $user; if ( my $store = $config->{auth_store} ) { $store = $c->get_auth_store($store) unless ref $store; - $user = $store->get_user( \%parameters ); + $user = $store->get_user( $p, $res ); } else { my $user_class = $config->{user_class}; $user_class->require or die $@; - $user = $user_class->new( \%parameters ); + $user = $user_class->new( $res ); } $c->set_authenticated($user); @@ -74,7 +71,7 @@ sub authenticate_typekey { else { $c->log->debug( sprintf "Failed to authenticate user '%s'. Reason: '%s'", - $parameters{name}, $typekey->errstr ) + $p->{name} || $p->param("name"), $typekey->errstr ) if $c->debug; return; @@ -92,19 +89,26 @@ for Catalyst. =head1 SYNOPSIS - use Catalyst qw[Authentication::Credential::TypeKey]; + use Catalyst qw/Authentication::Credential::TypeKey/; - MyApp->config->{authenticate}->{typekey} = { - token => 'xxxxxxxxxxxxxxxxxxxx' + MyApp->config->{authentication}{typekey} = { + token => 'xxxxxxxxxxxxxxxxxxxx', }; sub foo : Local { my ( $self, $c ) = @_; - if ( $c->authenticate_typekey( name => $name, email => $email, ... ) ) { + if ( $c->authenticate_typekey ) { + + # you can also specify the params manually: $c->authenticate_typekey( + # name => $name, + # email => $email, + # ... + #) + # successful autentication - $c->user; # blah + $c->user; # this is set } } @@ -112,11 +116,30 @@ for Catalyst. sub auto : Private { my ( $self, $c ) = @_; - $c->authenticate_typekey; # uses $c->req->params + $c->authenticate_typekey; # uses $c->req return 1; } +=head1 TYPEKEY BROKED-NESS + +Please watch: + + http://rt.cpan.org/NoAuth/Bugs.html?Dist=Authen-TypeKey + +I could only get this to properly work with TypeKey version 1 (not 1.1). + +To get around this problem configure the plugin to use version 1: + + __PACKAGE__->config( + authentication => { + typekey => { + version => 1, + token => ..., # doesn't really matter in version 1 + }, + }, + ); + =head1 DESCRIPTION This module integrates L with @@ -169,9 +192,11 @@ A store (or store name) to retrieve the user from. When a user is successfully authenticated it will call this: - $store->get_user( $parameters ); + $store->get_user( $parameters, $result_of_verify ); -Where C<$parameters> is a the hash reference passed to L. +Where C<$parameters> is a the hash reference passed to +L, and C<$result_of_verify> is the value returned by +L. =item user_class