fixed pod
[catagits/Catalyst-Plugin-Authentication.git] / lib / Catalyst / Plugin / Authentication / Store.pod
CommitLineData
22c223db 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
26=head1 WORKING WITH USERS
27
28All credential verifiers should accept either a user object, or a user ID.
29
30If a user ID is provided, then they will fetch the user object from the default
31store, and check against it.
32
33This should be pretty much DWIM all the time.
34
35When you need multiple authentication backends per application then you must
36fetch things yourself. For example:
37
38 my $user = $c->get_auth_store("other_store")->get_user($id);
39
40 $c->login( $user, $supplied_password );
41
fca3d744 42Instead of just:
43
44 $c->login( $id, $supplied_password );
45
46which will go to the default store.
47
22c223db 48=head1 WRITING A BACKEND
49
50Writing an authentication storage backend is a very simple matter.
51
52The only method you really need to support is C<get_user>.
53
54This method should accept an arbitrary list of parameters (determined by you or
55the credential verifyer), and return an object inheriting
56L<Catalyst::Plugin::Authentication::User>.
57
58For introspection purposes you can also define the C<user_supports> method. See
59below for optional features. This is not necessary, but might be in the future.
60
61=head2 Integrating with Catalyst::Plugin::Session
62
63If your users support sessions, your store should also define the
64C<from_session> method. When the user object is saved in the session the
65C<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
67C<<$user->store>> returns something registered, that store's name is used. If
68not, the user's class is used as if it were a store (and must also support
69C<from_session>).
70
71=head2 Optional Features
72
73Each user has the C<supports> method. For example:
74
75 $user->supports(qw/password clear/);
76
77should return a true value if this specific user has a clear text password.
78
79This is on a per user (not necessarily a per store) basis. To make assumptions
80about the store as a whole,
81
82 $store->user_supports(qw/password clear/);
83
84is supposed to be the lowest common denominator.
85
86The standardization of these values is to be goverened by the community,
87typically defined by the credential verification plugins.
88
89=head2 Stores implying certain credentials
90
91Sometimes a store is agnostic to the credentials (DB storage, for example), but
92sometimes it isn't (like an Htpasswd file).
93
94If you are writing a backend that wraps around a module, like
95L<Catalyst::Plugin::Authentication::Store::Htpasswd> wraps around
96L<Authen::Htpasswd>, it makes sense to delegate the credential checks.
97
98This particular example caused the following "feature" to be added:
99
100 $user->supports(qw/password self_check/);
101
102=head2 Writing a plugin to go with the backend
103
104Typically the backend will do the heavy lifting, by registering a store.
105
106These plugins should look something like this:
107
108 sub setup {
109 my $c = shift;
110
111 $c->default_auth_store(
112 # a store can be an object or a class
113 Catalyst::Plugin::Authentication::Store::Foo::Backend->new(
114 ...
115 )
116 );
117
118 $c->NEXT::setup(@_);
119 }