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 skip_expiry_check/) {
31 $typekey->$_( $config->{$_} );
40 sub authenticate_typekey {
42 my $p = @p ? { @p } : undef;
44 my $config = $c->config->{authentication}{typekey};
46 my $typekey = $p && delete( $p->{typekey_object} )
47 || $config->{typekey_object};
51 if ( my $res = $typekey->verify( $p ) ) {
52 $c->log->debug("Successfully authenticated user '$res->{name}'.")
57 if ( my $store = $config->{auth_store} ) {
58 $store = $c->get_auth_store($store) unless ref $store;
59 $user = $store->get_user( $p, $res );
62 my $user_class = $config->{user_class};
63 $user_class->require or die $@;
64 $user = $user_class->new( $res );
67 $c->set_authenticated($user);
73 sprintf "Failed to authenticate user '%s'. Reason: '%s'",
74 $p->{name} || $p->param("name"), $typekey->errstr )
87 Catalyst::Plugin::Authentication::Credential::TypeKey - TypeKey Authentication
92 use Catalyst qw/Authentication::Credential::TypeKey/;
94 MyApp->config->{authentication}{typekey} = {
95 token => 'xxxxxxxxxxxxxxxxxxxx',
99 my ( $self, $c ) = @_;
101 if ( $c->authenticate_typekey ) {
103 # you can also specify the params manually: $c->authenticate_typekey(
109 # successful autentication
111 $c->user; # this is set
117 my ( $self, $c ) = @_;
119 $c->authenticate_typekey; # uses $c->req
124 =head1 TYPEKEY BROKED-NESS
128 http://rt.cpan.org/NoAuth/Bugs.html?Dist=Authen-TypeKey
130 I could only get this to properly work with TypeKey version 1 (not 1.1).
132 To get around this problem configure the plugin to use version 1:
138 token => ..., # doesn't really matter in version 1
145 This module integrates L<Authen::TypeKey> with
146 L<Catalyst::Plugin::Authentication>.
150 =item authenticate_typekey %parameters
152 =item authenticate_typekey
154 =item EXTENDED METHODS
158 Fills the config with defaults.
162 C<<$c->config->{autentication}{typekey}>> is a hash with these fields (all can
169 If this field does not exist an L<Authen::TypeKey> object will be created based
170 on the other param and put here.
180 See L<Authen::TypeKey> for all of these. If they aren't specified
181 L<Authen::TypeKey>'s defaults will be used.
185 Also see L<Authen::TypeKey>.
187 Defaults to C<regkeys.txt> under L<Catalyst::Utils/class2tempdir>.
191 A store (or store name) to retrieve the user from.
193 When a user is successfully authenticated it will call this:
195 $store->get_user( $parameters, $result_of_verify );
197 Where C<$parameters> is a the hash reference passed to
198 L<Authen::TypeKey/verify>, and C<$result_of_verify> is the value returned by
199 L<Authen::TypeKey/verify>.
203 If C<auth_store> is not set it will use this class to instantiate an object,
204 calling C<new> on the class with the same C<$parameters> hash ref.
210 L<Authen::TypeKey>, L<Catalyst>, L<Catalyst::Plugin::Authentication>.
216 Yuval Kogman, C<nothingmuch@woobling.org>
220 This library is free software . You can redistribute it and/or modify it under
221 the same terms as perl itself.