NAME
Catalyst::Authentication::Credential::HTTP - HTTP Basic and Digest authentication for Catalyst.
SYNOPSIS
use Catalyst qw/
Authentication
/;
__PACKAGE__->config( authentication => {
realms => {
example => {
credential => {
class => 'HTTP',
type => 'any', # or 'digest' or 'basic'
password_type => 'clear',
password_field => 'password'
},
store => {
class => 'Minimal',
users => {
Mufasa => { password => "Circle Of Life", },
},
},
},
}
});
sub foo : Local {
my ( $self, $c ) = @_;
$c->authenticate({ realm => "example" });
# either user gets authenticated or 401 is sent
do_stuff();
}
# with ACL plugin
__PACKAGE__->deny_access_unless("/path", sub { $_[0]->authenticate });
DESCRIPTION
This module lets you use HTTP authentication with Catalyst::Plugin::Authentication. Both basic and digest authentication are currently supported.
When authentication is required, this module sets a status of 401, and the body of the response to 'Authorization required.'. To override this and set your own content, check for the $c->res->status == 401
in your end
action, and change the body accordingly.
TERMS
- Nonce
-
A nonce is a one-time value sent with each digest authentication request header. The value must always be unique, so per default the last value of the nonce is kept using Catalyst::Plugin::Cache. To change this behaviour, override the
store_digest_authorization_nonce
andget_digest_authorization_nonce
methods as shown below.
METHODS
- new $config, $c, $realm
-
Simple constructor.
- authenticate $c, $realm, \%auth_info
-
Tries to authenticate the user, and if that fails calls
authorization_required_response
and detaches the current action call stack.Looks inside
$c->request->headers
and processes the digest and basic (badly named) authorization header.This will only try the methods set in the configuration. First digest, then basic.
This method just passes the options through untouched. See the next two methods for what \%auth_info can contain.
- authenticate_basic $c, $realm, \%auth_info
-
Acts like Catalyst::Authentication::Credential::Password, and will lookup the user's password as detailed in that module.
- authenticate_digest $c, $realm, \%auth_info
-
Assumes that your user object has a hard coded method which returns a clear text password.
-
Sets
$c->response
to the correct status code, and adds the correct header to demand authentication data from the user agent.Typically used by
authenticate
, but may be invoked manually.%opts can contain
domain
andalgorithm
, which are used to build %the digest header. -
Set or get the
$nonce
object used by the digest auth mode.You may override these methods. By default they will call
get
andset
on$c->cache
.
CONFIGURATION
All configuration is stored in YourApp->config(authentication => { yourrealm => { credential => { class => 'HTTP', %config } } }
.
This should be a hash, and it can contain the following entries:
- type
-
Can be either
any
(the default),basic
ordigest
.This controls
authorization_required_response
andauthenticate
, but not the "manual" methods. -
Set this to a string to override the default body content "Authorization required.", or set to undef to suppress body content being generated.
RESTRICTIONS
When using digest authentication, this module will only work together with authentication stores whose User objects have a password
method that returns the plain-text password. It will not work together with Catalyst::Authentication::Store::Htpasswd, or Catalyst::Authentication::Store::DBIC stores whose password
methods return a hashed or salted version of the password.
AUTHORS
Updated to current name space and currently maintained by: Tomas Doran bobtfish@bobtfish.net
.
Original module by:
SEE ALSO
RFC 2617 (or its successors), Catalyst::Plugin::Cache, Catalyst::Plugin::Authentication
COPYRIGHT & LICENSE
Copyright (c) 2005-2008 the aforementioned authors. All rights
reserved. This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.