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=ba4511c9d797db710e28b76de57b81b2ee809abe;hb=8a4cd23ab3f06a2f14e366fc0629bba279959e7f;hp=0000000000000000000000000000000000000000;hpb=2e823d32460ec0c06cb0ba1cdc42b26f97dadf3a;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 new file mode 100644 index 0000000..ba4511c --- /dev/null +++ b/lib/Catalyst/Plugin/Authentication/Credential/TypeKey.pm @@ -0,0 +1,99 @@ +package Catalyst::Plugin::Authentication::Credential::TypeKey; + +use strict; +use Authen::TypeKey; +use Carp (); +use File::Spec; + +our $VERSION = '0.1'; + +our $PARAMETERS = qw[ + email + name + nick + ts + sig +]; + +sub authenticate_typekey { + my ( $c, $email, $name, $nick, $ts, $sig, $options ) = @_; + + unless ( @_ == 6 || ( @_ == 7 && ref($options) eq 'HASH' ) ) { + Carp::croak('usage: $c->authenticate_typekey( $email, $name, $nick, $ts, $sig [, \%options ] )'); + } + + unless ( @_ == 7 ) { + $options = {}; + } + + my $config = $c->config->{authenticate}->{typekey}; + + my $token = $options->{token} || $config->{token} || undef; + my $expires = $options->{expires} || $config->{expires} || 0; + my $version = $options->{version} || $config->{version} || 1.1; + my $cache = $options->{cache} || $config->{cache} || File::Spec->catfile( File::Spec->tmpdir, 'regkeys.txt' ); + my $keys = $options->{keys} || $config->{keys} || 'http://www.typekey.com/extras/regkeys.txt'; + + my $typekey = Authen::TypeKey->new; + $typekey->expires($expires); + $typekey->key_cache($cache); + $typekey->key_url($keys); + $typekey->token($token); + $typekey->version($version); + + my $parameters = { + email => $email, + name => $name, + nick => $nick, + ts => $ts, + sig => $sig + }; + + unless ( $typekey->verify($parameters) ) { + my $error = $typekey->errstr; + $c->log->debug(qq/Failed to authenticate user '$name'. Reason: '$error'/); + return 0; + } + + $c->log->debug( qq/Successfully authenticated user '$name'./); + return 1; +} + +1; + +__END__ + +=head1 NAME + +Catalyst::Plugin::Authentication::Credential::TypeKey - TypeKey Authentication + +=head1 SYNOPSIS + + use Catalyst qw[Authentication::Credential::TypeKey]; + + MyApp->config->{authenticate}->{typekey} = { + token => 'xxxxxxxxxxxxxxxxxxxx' + }; + + if ( $c->authenticate_typekey( $email, $name, $nick, $ts, $sig ) ) { + # successful autentication + } + +=head1 DESCRIPTION + +TypeKey Authentication. + +=head1 SEE ALSO + +L, L. + +=head1 AUTHOR + +Christian Hansen, C + +=head1 LICENSE + +This library is free software . You can redistribute it and/or modify it under +the same terms as perl itself. + +=cut