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