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 ) );
74 my $cfg = $c->config->{authentication};
92 Catalyst::Plugin::Authentication -
98 Authentication::Store::Foo
99 Authentication::Credential::Password
104 The authentication plugin is used by the various authentication and
105 authorization plugins in catalyst.
107 It defines the notion of a logged in user, and provides integration with the
115 Delete the currently logged in user from C<user> and the session.
119 Returns the currently logged user or undef if there is none.
123 Delegate C<get_user> to the default store.
125 =item default_auth_store
127 Returns C<< $c->config->{authentication}{store} >>.
131 =head1 INTERNAL METHODS
135 =item set_authenticated $user
137 Marks a user as authenticated. Should be called from a
138 C<Catalyst::Plugin::Authentication::Credential> plugin after successful
141 This involves setting C<user> and the internal data in C<session> if
142 L<Catalyst::Plugin::Session> is loaded.
146 Revives a user from the session object if there is one.
150 Sets the default configuration parameters.
162 Whether or not to store the user's logged in state in the session, if the
163 application is also using the L<Catalyst::Plugin::Authentication> plugin.