1 package Catalyst::Plugin::Authentication::Credential::TypeKey;
8 use Catalyst::Utils ();
10 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" )->require;
24 $config->{key_cache} ||=
25 File::Spec->catfile( Catalyst::Utils::class2tempdir( $c, 1 ),
28 my $typekey = Authen::TypeKey->new;
30 for ( grep { exists $config->{$_} }
31 qw/expires key_cache key_url token version skip_expiry_check/ )
33 $typekey->$_( $config->{$_} );
42 sub authenticate_typekey {
47 if ( Scalar::Util::blessed( $p[0] ) ) {
49 Catalyst::Exception->throw(
50 "Attempted to authenticate user object, but "
51 . "user doesnt't support 'typekey_credentials'" )
52 unless $user->supports(qw/typekey_credentials/);
53 $p = $user->typekey_credentials;
60 $p = @p ? {@p} : undef;
63 my $config = $c->config->{authentication}{typekey};
65 my $typekey = $p && delete( $p->{typekey_object} )
66 || $config->{typekey_object};
70 if ( my $res = $typekey->verify($p) ) {
71 $c->log->debug("Successfully authenticated user '$res->{name}'.")
74 if ( !$user and my $store = $config->{auth_store} ) {
75 $store = $c->get_auth_store($store) unless ref $store;
76 $user = $store->get_user( $p, $res );
80 my $user_class = $config->{user_class};
81 $user = $user_class->new($res);
84 $c->set_authenticated($user);
90 sprintf "Failed to authenticate user '%s'. Reason: '%s'",
91 $p->{name} || $p->param("name"),
106 Catalyst::Plugin::Authentication::Credential::TypeKey - TypeKey Authentication
111 use Catalyst qw/Authentication::Credential::TypeKey/;
113 MyApp->config->{authentication}{typekey} = {
114 token => 'xxxxxxxxxxxxxxxxxxxx',
118 my ( $self, $c ) = @_;
120 if ( $c->authenticate_typekey ) {
122 # you can also specify the params manually: $c->authenticate_typekey(
128 # successful autentication
130 $c->user; # this is set
136 my ( $self, $c ) = @_;
138 $c->authenticate_typekey; # uses $c->req
143 =head1 TYPEKEY BROKED-NESS
147 http://rt.cpan.org/NoAuth/Bugs.html?Dist=Authen-TypeKey
149 I could only get this to properly work with TypeKey version 1 (not 1.1).
151 To get around this problem configure the plugin to use version 1:
157 token => ..., # doesn't really matter in version 1
164 This module integrates L<Authen::TypeKey> with
165 L<Catalyst::Plugin::Authentication>.
169 =head3 authenticate_typekey %parameters
171 =head3 authenticate_typekey
173 =head3 EXTENDED METHODS
177 Fills the config with defaults.
181 C<<$c->config->{autentication}{typekey}>> is a hash with these fields (all can
188 If this field does not exist an L<Authen::TypeKey> object will be created based
189 on the other param and put here.
199 See L<Authen::TypeKey> for all of these. If they aren't specified
200 L<Authen::TypeKey>'s defaults will be used.
204 Also see L<Authen::TypeKey>.
206 Defaults to C<regkeys.txt> under L<Catalyst::Utils/class2tempdir>.
210 A store (or store name) to retrieve the user from.
212 When a user is successfully authenticated it will call this:
214 $store->get_user( $parameters, $result_of_verify );
216 Where C<$parameters> is a the hash reference passed to
217 L<Authen::TypeKey/verify>, and C<$result_of_verify> is the value returned by
218 L<Authen::TypeKey/verify>.
220 If this is unset, L<Catalyst::Plugin::Authentication/default_auth_store> will
225 If C<auth_store> or the default store returns nothing from get_user, this class
226 will be used to instantiate an object by calling C<new> on the class with the
227 return value from L<Authen::TypeKey/verify>.
233 L<Authen::TypeKey>, L<Catalyst>, L<Catalyst::Plugin::Authentication>.
239 Yuval Kogman, C<nothingmuch@woobling.org>
243 This library is free software . You can redistribute it and/or modify it under
244 the same terms as perl itself.