doc fix in C::P::Auth + debug messages in C::P::Auth::Cred::Password
[catagits/Catalyst-Plugin-Authentication.git] / lib / Catalyst / Plugin / Authentication / Store.pod
CommitLineData
6876341d 1
2=head1 NAME
3
4Catalyst::Plugin::Authentication::Store - All about authentication stores
5
6=head1 MULTIPLE BACKENDS
7
8A key issue to understand about authentication stores is that there are
9potentially many of them. Each one is registered into the application, and has
10a name.
11
12For most applications, there is only one, and in this framework it is called
13'default'.
14
15When you use a plugin, like
16
17 use Catalyst qw/
18 Authentication
19 Authentication::Store::Foo
20 /;
21
22the Store plugins typically only act at setup time. They rarely do more than
23check out the configuration, and register e.g. Store::Foo::Backend, and set it
24as the default store.
25
59f1e010 26 __PACKAGE__->default_auth_store( $store );
27
28 # the same as
29
30 __PACKAGE__->register_auth_stores( default => $store );
31
6876341d 32=head1 WORKING WITH USERS
33
34All credential verifiers should accept either a user object, or a user ID.
35
36If a user ID is provided, then they will fetch the user object from the default
37store, and check against it.
38
39This should be pretty much DWIM all the time.
40
41When you need multiple authentication backends per application then you must
42fetch things yourself. For example:
43
44 my $user = $c->get_auth_store("other_store")->get_user($id);
45
46 $c->login( $user, $supplied_password );
47
69271f57 48Instead of just:
49
50 $c->login( $id, $supplied_password );
51
52which will go to the default store.
53
6876341d 54=head1 WRITING A BACKEND
55
56Writing an authentication storage backend is a very simple matter.
57
58The only method you really need to support is C<get_user>.
59
60This method should accept an arbitrary list of parameters (determined by you or
61the credential verifyer), and return an object inheriting
62L<Catalyst::Plugin::Authentication::User>.
63
64For introspection purposes you can also define the C<user_supports> method. See
65below for optional features. This is not necessary, but might be in the future.
66
67=head2 Integrating with Catalyst::Plugin::Session
68
69If your users support sessions, your store should also define the
70C<from_session> method. When the user object is saved in the session the
71C<for_session> method is called, and that is used as the value in the session
72(typically a user id). The store is also saved in the hash. If
73C<<$user->store>> returns something registered, that store's name is used. If
74not, the user's class is used as if it were a store (and must also support
75C<from_session>).
76
77=head2 Optional Features
78
79Each user has the C<supports> method. For example:
80
81 $user->supports(qw/password clear/);
82
83should return a true value if this specific user has a clear text password.
84
85This is on a per user (not necessarily a per store) basis. To make assumptions
86about the store as a whole,
87
88 $store->user_supports(qw/password clear/);
89
90is supposed to be the lowest common denominator.
91
92The standardization of these values is to be goverened by the community,
93typically defined by the credential verification plugins.
94
95=head2 Stores implying certain credentials
96
97Sometimes a store is agnostic to the credentials (DB storage, for example), but
98sometimes it isn't (like an Htpasswd file).
99
100If you are writing a backend that wraps around a module, like
101L<Catalyst::Plugin::Authentication::Store::Htpasswd> wraps around
102L<Authen::Htpasswd>, it makes sense to delegate the credential checks.
103
104This particular example caused the following "feature" to be added:
105
106 $user->supports(qw/password self_check/);
107
108=head2 Writing a plugin to go with the backend
109
110Typically the backend will do the heavy lifting, by registering a store.
111
112These plugins should look something like this:
113
114 sub setup {
115 my $c = shift;
116
117 $c->default_auth_store(
118 # a store can be an object or a class
119 Catalyst::Plugin::Authentication::Store::Foo::Backend->new(
120 ...
121 )
122 );
123
124 $c->NEXT::setup(@_);
125 }