4 Catalyst::Plugin::Authentication::Store - All about authentication stores
6 =head1 MULTIPLE BACKENDS
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
12 For most applications, there is only one, and in this framework it is called
15 When you use a plugin, like
19 Authentication::Store::Foo
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
26 =head1 WORKING WITH USERS
28 All credential verifiers should accept either a user object, or a user ID.
30 If a user ID is provided, then they will fetch the user object from the default
31 store, and check against it.
33 This should be pretty much DWIM all the time.
35 When you need multiple authentication backends per application then you must
36 fetch things yourself. For example:
38 my $user = $c->get_auth_store("other_store")->get_user($id);
40 $c->login( $user, $supplied_password );
44 $c->login( $id, $supplied_password );
46 which will go to the default store.
48 =head1 WRITING A BACKEND
50 Writing an authentication storage backend is a very simple matter.
52 The only method you really need to support is C<get_user>.
54 This method should accept an arbitrary list of parameters (determined by you or
55 the credential verifyer), and return an object inheriting
56 L<Catalyst::Plugin::Authentication::User>.
58 For introspection purposes you can also define the C<user_supports> method. See
59 below for optional features. This is not necessary, but might be in the future.
61 =head2 Integrating with Catalyst::Plugin::Session
63 If your users support sessions, your store should also define the
64 C<from_session> method. When the user object is saved in the session the
65 C<for_session> method is called, and that is used as the value in the session
66 (typically a user id). The store is also saved in the hash. If
67 C<<$user->store>> returns something registered, that store's name is used. If
68 not, the user's class is used as if it were a store (and must also support
71 =head2 Optional Features
73 Each user has the C<supports> method. For example:
75 $user->supports(qw/password clear/);
77 should return a true value if this specific user has a clear text password.
79 This is on a per user (not necessarily a per store) basis. To make assumptions
80 about the store as a whole,
82 $store->user_supports(qw/password clear/);
84 is supposed to be the lowest common denominator.
86 The standardization of these values is to be goverened by the community,
87 typically defined by the credential verification plugins.
89 =head2 Stores implying certain credentials
91 Sometimes a store is agnostic to the credentials (DB storage, for example), but
92 sometimes it isn't (like an Htpasswd file).
94 If you are writing a backend that wraps around a module, like
95 L<Catalyst::Plugin::Authentication::Store::Htpasswd> wraps around
96 L<Authen::Htpasswd>, it makes sense to delegate the credential checks.
98 This particular example caused the following "feature" to be added:
100 $user->supports(qw/password self_check/);
102 =head2 Writing a plugin to go with the backend
104 Typically the backend will do the heavy lifting, by registering a store.
106 These plugins should look something like this:
111 $c->default_auth_store(
112 # a store can be an object or a class
113 Catalyst::Plugin::Authentication::Store::Foo::Backend->new(