3 package Catalyst::Plugin::Authentication;
5 use base qw/Class::Accessor::Fast Class::Data::Inheritable/;
8 __PACKAGE__->mk_accessors(qw/user/);
9 __PACKAGE__->mk_classdata(qw/default_auth_store/);
15 our $VERSION = "0.01";
17 sub set_authenticated {
18 my ( $c, $user ) = @_;
22 if ( $c->isa("Catalyst::Plugin::Session")
23 and $c->config->{authentication}{use_session} )
25 $c->session->{__user} = $user->for_session
26 if $user->supports("session");
27 $c->session->{__user_class} = ref $user;
36 if ( $c->isa("Catalyst::Plugin::Session")
37 and $c->config->{authentication}{use_session} )
39 delete @{ $c->session }{qw/__user __user_class/};
46 if ( my $store = $c->default_auth_store ) {
47 return $store->get_user($uid);
50 Catalyst::Exception->throw(
51 "The user id $uid was passed to an authentication "
52 . "plugin, but no default store was specified" );
57 my $c = shift->NEXT::prepare(@_);
59 if ( $c->isa("Catalyst::Plugin::Session")
60 and $c->default_auth_store
63 if ( $c->sessionid and my $user = $c->session->{__user} ) {
64 $c->user( $c->session->{__user_class}->from_session( $c, $user ) );
65 $c->request->{user} = $c->user; # compatibility kludge
75 my $cfg = $c->config->{authentication};
93 Catalyst::Plugin::Authentication -
99 Authentication::Store::Foo
100 Authentication::Credential::Password
105 The authentication plugin is used by the various authentication and
106 authorization plugins in catalyst.
108 It defines the notion of a logged in user, and provides integration with the
116 Delete the currently logged in user from C<user> and the session.
120 Returns the currently logged user or undef if there is none.
124 Delegate C<get_user> to the default store.
126 =item default_auth_store
128 Returns C<< $c->config->{authentication}{store} >>.
132 =head1 INTERNAL METHODS
136 =item set_authenticated $user
138 Marks a user as authenticated. Should be called from a
139 C<Catalyst::Plugin::Authentication::Credential> plugin after successful
142 This involves setting C<user> and the internal data in C<session> if
143 L<Catalyst::Plugin::Session> is loaded.
147 Revives a user from the session object if there is one.
151 Sets the default configuration parameters.
163 Whether or not to store the user's logged in state in the session, if the
164 application is also using the L<Catalyst::Plugin::Authentication> plugin.