1 package Catalyst::Plugin::Authentication::Credential::TypeKey;
9 use Catalyst::Utils ();
11 use UNIVERSAL::require;
18 my $config = $c->config->{authentication}{typekey} ||= {};
20 $config->{typekey_object} ||= do {
21 $config->{user_class} ||=
22 "Catalyst::Plugin::Authentication::User::Hash";
24 $config->{key_cache} ||=
25 File::Spec->catfile( Catalyst::Utils::class2tempdir( $c, 1 ),
28 my $typekey = Authen::TypeKey->new;
30 for (grep { exists $config->{$_} } qw/expires key_cache key_url token version/) {
31 $typekey->$_( $config->{$_} );
40 sub authenticate_typekey {
41 my ( $c, %parameters ) = @_;
43 my $config = $c->config->{authentication}{typekey};
45 my $typekey = delete( $parameters{typekey_object} )
46 || $config->{typekey_object};
48 my @fields = qw/email name nick ts sig/;
50 foreach my $field (@fields) {
51 $parameters{$field} ||= $c->req->param($field) || return;
54 if ( $typekey->verify( \%parameters ) ) {
55 $c->log->debug("Successfully authenticated user '$parameters{name}'.")
60 if ( my $store = $config->{auth_store} ) {
61 $store = $c->get_auth_store($store) unless ref $store;
62 $user = $store->get_user( \%parameters );
65 my $user_class = $config->{user_class};
66 $user_class->require or die $@;
67 $user = $user_class->new( \%parameters );
70 $c->set_authenticated($user);
76 sprintf "Failed to authenticate user '%s'. Reason: '%s'",
77 $parameters{name}, $typekey->errstr )
90 Catalyst::Plugin::Authentication::Credential::TypeKey - TypeKey Authentication
95 use Catalyst qw[Authentication::Credential::TypeKey];
97 MyApp->config->{authenticate}->{typekey} = {
98 token => 'xxxxxxxxxxxxxxxxxxxx'
102 my ( $self, $c ) = @_;
104 if ( $c->authenticate_typekey( name => $name, email => $email, ... ) ) {
105 # successful autentication
113 my ( $self, $c ) = @_;
115 $c->authenticate_typekey; # uses $c->req->params
122 This module integrates L<Authen::TypeKey> with
123 L<Catalyst::Plugin::Authentication>.
127 =item authenticate_typekey %parameters
129 =item authenticate_typekey
131 =item EXTENDED METHODS
135 Fills the config with defaults.
139 C<<$c->config->{autentication}{typekey}>> is a hash with these fields (all can
146 If this field does not exist an L<Authen::TypeKey> object will be created based
147 on the other param and put here.
157 See L<Authen::TypeKey> for all of these. If they aren't specified
158 L<Authen::TypeKey>'s defaults will be used.
162 Also see L<Authen::TypeKey>.
164 Defaults to C<regkeys.txt> under L<Catalyst::Utils/class2tempdir>.
168 A store (or store name) to retrieve the user from.
170 When a user is successfully authenticated it will call this:
172 $store->get_user( $parameters );
174 Where C<$parameters> is a the hash reference passed to L<Authen::TypeKey/verify>.
178 If C<auth_store> is not set it will use this class to instantiate an object,
179 calling C<new> on the class with the same C<$parameters> hash ref.
185 L<Authen::TypeKey>, L<Catalyst>, L<Catalyst::Plugin::Authentication>.
191 Yuval Kogman, C<nothingmuch@woobling.org>
195 This library is free software . You can redistribute it and/or modify it under
196 the same terms as perl itself.