3 package Catalyst::Plugin::Authentication;
5 use base qw/Class::Accessor::Fast/;
7 BEGIN { __PACKAGE__->mk_accessors(qw/user/) }
12 sub default_auth_store {
14 $c->config->{authentication}{store};
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->supperts("session");
27 $c->session->{__user_class} = ref $user;
35 delete @{ $c->session }{qw/__user __user_class/};
41 if ( my $store = $c->default_auth_store ) {
42 return $store->get_user($uid);
45 Catalyst::Exception->throw(
46 "The user id $uid was passed to an authentication "
47 . "plugin, but no default store was specified" );
52 my $c = shift->NEXT::prepare(@_);
54 if ( $c->isa("Catalyst::Plugin::Session")
55 and $c->config->{authentication}{use_session}
58 if ( $c->sessionid and my $user = $c->session->{__user} ) {
59 $c->user( $c->session->{__user_class}->from_session( $c, $user ) );
69 my $cfg = $c->config->{authentication};
85 Catalyst::Plugin::Authentication -
91 Authentication::Store::Foo
92 Authentication::Credential::Password
97 The authentication plugin is used by the various authentication and
98 authorization plugins in catalyst.
100 It defines the notion of a logged in user, and provides integration with the
108 Delete the currently logged in user from C<user> and the session.
112 Returns the currently logged user or undef if there is none.
116 Delegate C<get_user> to the default store.
118 =item default_auth_store
120 Returns C<< $c->config->{authentication}{store} >>.
124 =head1 INTERNAL METHODS
128 =item set_authenticated $user
130 Marks a user as authenticated. Should be called from a
131 C<Catalyst::Plugin::Authentication::Credential> plugin after successful
134 This involves setting C<user> and the internal data in C<session> if
135 L<Catalyst::Plugin::Session> is loaded.
139 Revives a user from the session object if there is one.
143 Sets the default configuration parameters.
155 Whether or not to store the user's logged in state in the session, if the
156 application is also using the L<Catalyst::Plugin::Authentication> plugin.