From: Christian Hansen Date: Thu, 2 Jun 2005 16:06:28 +0000 (+0000) Subject: Initial import of Catalyst::Plugin::Authenticate::TypeKey X-Git-Tag: v0.03~27 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Authentication-Credential-HTTP-Proxy.git;a=commitdiff_plain;h=3bb8633b97fea01c9c496401a4992180b5b44e84 Initial import of Catalyst::Plugin::Authenticate::TypeKey --- 3bb8633b97fea01c9c496401a4992180b5b44e84 diff --git a/lib/Catalyst/Plugin/Authenticate/TypeKey.pm b/lib/Catalyst/Plugin/Authenticate/TypeKey.pm new file mode 100644 index 0000000..d6dc8e0 --- /dev/null +++ b/lib/Catalyst/Plugin/Authenticate/TypeKey.pm @@ -0,0 +1,91 @@ +package Catalyst::Plugin::Authenticate::TypeKey; + +use strict; +use Authen::TypeKey; +use Carp (); +use File::Spec; + +our $VERSION = '0.1'; + +sub authenticate_typekey { + my ( $c, $email, $name, $nick, $ts, $sig, $options ) = @_; + + unless ( @_ == 6 || ( @_ == 7 && ref($options) eq 'HASH' ) ) { + Carp::croak('usage: $c->authenticate_ldap( $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::Authenticate::TypeKey - TypeKey Authentication + +=head1 SYNOPSIS + + use Catalyst qw[Authenticate::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