Finish rename of typekey fork
[catagits/Catalyst-Authentication-Credential-HTTP-Proxy.git] / lib / Catalyst / Plugin / Authentication / Credential / TypeKey.pm
CommitLineData
2e823d32 1package Catalyst::Plugin::Authentication::Credential::TypeKey;
3bb8633b 2
3use strict;
4use Authen::TypeKey;
5use Carp ();
6use File::Spec;
7
8our $VERSION = '0.1';
9
e42cd610 10our $PARAMETERS = qw[
11 email
12 name
13 nick
14 ts
15 sig
16];
17
3bb8633b 18sub authenticate_typekey {
19 my ( $c, $email, $name, $nick, $ts, $sig, $options ) = @_;
20
21 unless ( @_ == 6 || ( @_ == 7 && ref($options) eq 'HASH' ) ) {
1f912a4a 22 Carp::croak('usage: $c->authenticate_typekey( $email, $name, $nick, $ts, $sig [, \%options ] )');
3bb8633b 23 }
24
25 unless ( @_ == 7 ) {
26 $options = {};
27 }
28
29 my $config = $c->config->{authenticate}->{typekey};
30
31 my $token = $options->{token} || $config->{token} || undef;
32 my $expires = $options->{expires} || $config->{expires} || 0;
33 my $version = $options->{version} || $config->{version} || 1.1;
34 my $cache = $options->{cache} || $config->{cache} || File::Spec->catfile( File::Spec->tmpdir, 'regkeys.txt' );
35 my $keys = $options->{keys} || $config->{keys} || 'http://www.typekey.com/extras/regkeys.txt';
36
37 my $typekey = Authen::TypeKey->new;
38 $typekey->expires($expires);
39 $typekey->key_cache($cache);
40 $typekey->key_url($keys);
41 $typekey->token($token);
42 $typekey->version($version);
43
44 my $parameters = {
45 email => $email,
46 name => $name,
47 nick => $nick,
48 ts => $ts,
49 sig => $sig
50 };
51
52 unless ( $typekey->verify($parameters) ) {
53 my $error = $typekey->errstr;
54 $c->log->debug(qq/Failed to authenticate user '$name'. Reason: '$error'/);
55 return 0;
56 }
57
58 $c->log->debug( qq/Successfully authenticated user '$name'./);
59 return 1;
60}
61
621;
63
64__END__
65
66=head1 NAME
67
2e823d32 68Catalyst::Plugin::Authentication::Credential::TypeKey - TypeKey Authentication
3bb8633b 69
70=head1 SYNOPSIS
71
2e823d32 72 use Catalyst qw[Authentication::Credential::TypeKey];
3bb8633b 73
74 MyApp->config->{authenticate}->{typekey} = {
75 token => 'xxxxxxxxxxxxxxxxxxxx'
76 };
77
78 if ( $c->authenticate_typekey( $email, $name, $nick, $ts, $sig ) ) {
79 # successful autentication
80 }
81
82=head1 DESCRIPTION
83
84TypeKey Authentication.
85
86=head1 SEE ALSO
87
88L<Authen::TypeKey>, L<Catalyst>.
89
90=head1 AUTHOR
91
92Christian Hansen, C<ch@ngmedia.com>
93
94=head1 LICENSE
95
96This library is free software . You can redistribute it and/or modify it under
97the same terms as perl itself.
98
99=cut