Catalyst::Authentication::Credential::HTTP(3pm) | User Contributed Perl Documentation | Catalyst::Authentication::Credential::HTTP(3pm) |
Catalyst::Authentication::Credential::HTTP - HTTP Basic and Digest authentication for Catalyst
version 1.018
use Catalyst qw/ Authentication /; __PACKAGE__->config( authentication => { default_realm => 'example', 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({}, "example"); # either user gets authenticated or 401 is sent # Note that the authentication realm sent to the client (in the # RFC 2617 sense) is overridden here, but this *does not* # effect the Catalyst::Authentication::Realm used for # authentication - to do that, you need # $c->authenticate({}, 'otherrealm') do_stuff(); } sub always_auth : Local { my ( $self, $c ) = @_; # Force authorization headers onto the response so that the user # is asked again for authentication, even if they successfully # authenticated. my $realm = $c->get_auth_realm('example'); $realm->credential->authorization_required_response($c, $realm); } # with ACL plugin __PACKAGE__->deny_access_unless("/path", sub { $_[0]->authenticate });
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.
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.
The %auth_info hash can contain a number of keys which control the authentication behaviour:
This list of domains defines the protection space. If a domain URI is an absolute path (starts with /), it is relative to the root URL of the server being accessed. An absolute URI in this list may refer to a different server than the one being accessed.
The client will use this list to determine the set of URIs for which the same authentication information may be sent.
If this is omitted or its value is empty, the client will assume that the protection space consists of all URIs on the responding server.
Therefore, if your application is not hosted at the root of this domain, and you want to prevent the authentication credentials for this application being sent to any other applications. then you should use the use_uri_for configuration option, and pass a domain of /.
The password_type must be clear for digest authentication to succeed. If you do not want to store your user passwords as clear text, you may instead store the MD5 digest in hex of the string '$username:$realm:$password'.
Catalyst::Plugin::Cache is used for persistent storage of the nonce values (see "Nonce"). It must be loaded in your application, unless you override the "store_digest_authorization_nonce" and "get_digest_authorization_nonce" methods as shown below.
Takes an additional parameter of algorithm, the possible values of which are 'MD5' (the default) and 'MD5-sess'. For more information about 'MD5-sess', see section 3.2.2.2 in RFC 2617.
Typically used by "authenticate", but may be invoked manually.
%opts can contain "domain" and "algorithm", which are used to build %the digest header.
You may override these methods. By default they will call "get" and "set" on "$c->cache".
All configuration is stored in "YourApp->config('Plugin::Authentication' => { yourrealm => { credential => { class => 'HTTP', %config } } }".
This should be a hash, and it can contain the following entries:
This controls "authorization_required_response" and "authenticate", but not the "manual" methods.
However use like this is probably not optimum it also means that users in browsers ill never get a HTTP authenticate dialogue box (unless you manually return a 401 response in your application), and even some automated user agents (for APIs) will not send the Authorization header without specific manipulation of the request headers.
This option has no effect on clients that include the query string; they will continue to work as normal.
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.
RFC 2617 (or its successors), Catalyst::Plugin::Cache, Catalyst::Plugin::Authentication
Bugs may be submitted through the RT bug tracker <https://rt.cpan.org/Public/Dist/Display.html?Name=Catalyst-Authentication-Credential-HTTP> (or bug-Catalyst-Authentication-Credential-HTTP@rt.cpan.org <mailto:bug-Catalyst-Authentication-Credential-HTTP@rt.cpan.org>).
There is also a mailing list available for users of this distribution, at <http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst>.
There is also an irc channel available for users of this distribution, at "#catalyst" on "irc.perl.org" <irc://irc.perl.org/#catalyst>.
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
This software is copyright (c) 2006 by יובל קוג'מן (Yuval Kogman).
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
2022-06-09 | perl v5.34.0 |