Added Catalyst::Plugin::Authentication::Credential::NoPassword
[catagits/Catalyst-Plugin-Authentication.git] / lib / Catalyst / Plugin / Authentication / Credential / NoPassword.pm
CommitLineData
8a31d23d 1package Catalyst::Authentication::Credential::NoPassword;
2
3use Moose;
4use utf8;
5
6has 'realm' => (is => 'ro', required => 1);
7
8around BUILDARGS => sub {
9 my $orig = shift;
10 my $class = shift;
11
12 if ( @_ == 3 ) {
13 my ($config, $app, $realm) = @_;
14 return $class->$orig( realm => $realm );
15 }
16 else {
17 return $class->$orig(@_);
18 }
19};
20
21sub authenticate {
22 my ($self, $c, $realm, $authinfo) = @_;
23 $self->realm->find_user($authinfo, $c);
24}
25
261;
27
28__END__
29
30=head1 NAME
31
32Catalyst::Authentication::Credential::NoPassword - Authenticate a user
33without a password.
34
35=head1 SYNOPSIS
36
37 use Catalyst qw/
38 Authentication
39 /;
40
41 package MyApp::Controller::Auth;
42
43 sub login_as_another_user : Local {
44 my ($self, $c) = @_;
45
46 if ($c->user_exists() and $c->user->username() eq 'root') {
47 $c->authenticate( {id => c->req->params->{user_id}}, 'nopassword' );
48 }
49 }
50
51=head1 DESCRIPTION
52
53This authentication credential checker takes authentication information
54(most often a username) and retrieves the user from the store. No validation
55of any credentials is done. This is intended for administrative backdoors,
56SAML logins and so on when you have identified the new user by other means.
57
58=head1 CONFIGURATION
59
60 # example
61 <Plugin::Authentication>
62 <nopassword>
63 <credential>
64 class = NoPassword
65 </credential>
66 <store>
67 class = DBIx::Class
68 user_model = DB::User
69 role_relation = roles
70 role_field = name
71 </store>
72 </nopassword>
73 </Plugin::Authentication>
74
75=head1 METHODS
76
77=head2 authenticate ( $c, $realm, $authinfo )
78
79Try to log a user in.
80
81=cut