Cataly...::HTTP(3pm)
π Catalyst::Authentication::Credential::HTTP β the manual page β¨
okay so before we even start: this page lives in the User Contributed Perl Documentation section, and if you've ever seen Cataly...::HTTP(3pm) flash past in your terminal, congrats bestie, that's this page β it's just Catalyst::Authentication::Credential::HTTP wearing a name that got truncated by the terminal. iconic behavior. π
πΈ NAME πΈ
Catalyst::Authentication::Credential::HTTP β HTTP Basic and Digest authentication for Catalyst
π VERSION π
version 1.019
β¨ SYNOPSIS β¨
okay so here's the whole vibe of how you actually wire this thing up:
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 });
quick lil heads up: see that comment about the realm up there? The realm you hand to the client (RFC 2617 style) gets overridden by this call, but that does not touch theCatalyst::Authentication::Realmdoing the actual authenticating. For that you need$c->authenticate({}, 'otherrealm'). do not mix these up bestie, they will humble you.
π¦ DESCRIPTION π¦
This module is how you do HTTP authentication with Catalyst::Plugin::Authentication. Right now it supports both basic and digest authentication. slay.
When authentication is needed, this module sets a status of 401, and sets the body of the response to 'Authorization required.'. If you wanna override that and put your own content in there, go check for $c->res->status == 401 in your "end" action, and change the body however you like. π
π§ TERMS π§
- Nonce β a nonce is a one-time value sent with every single digest authentication request header. It literally has to be unique every time, so by default the last value of the nonce is kept using
Catalyst::Plugin::Cache. Wanna change that? Override thestore_digest_authorization_nonceandget_digest_authorization_noncemethods β shown below, iykyk.
π METHODS π
new $config, $c, $realm
Simple constructor. no drama, just vibes. β¨
init
Validates that $config is ok. That's it, that's the method.
authenticate $c, $realm, \%auth_info
Tries to authenticate the user, and if that fails it calls authorization_required_response and detaches the current action call stack. π«Ά
It looks inside $c->request->headers and processes the digest and basic (badly named, ngl) authorization header.
This will only try the methods you set in the configuration. First digest, then basic. periodt.
The %auth_info hash can carry a bunch of keys that control how the authentication behaves:
realmβ sets the HTTP authentication realm presented to the client. Note bestie: this does not alter theCatalyst::Authentication::Realmobject used for the authentication.domainβ array reference to domains used to build the authorization headers.- 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_forconfiguration option, and pass a domain of/. (yes this is the one that saves you from leaking creds around your server, lowkey important)
- This list of domains defines the protection space. If a domain URI is an absolute path (starts with
authenticate_basic $c, $realm, \%auth_info
Performs HTTP basic authentication.
authenticate_digest $c, $realm, \%auth_info
Performs HTTP digest authentication.
The password_type must be clear for digest authentication to succeed. If you don't wanna store your user passwords as clear text, you may instead store the MD5 digest in hex of the string '$username:$realm:$password'. (that's the escape hatch, use it)
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 info about 'MD5-sess', see section 3.2.2.2 in RFC 2617. π
authorization_required_response $c, $realm, \%auth_info
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 you're absolutely allowed to invoke it manually. main character energy. π
%opts can contain "domain" and "algorithm", which are used to build %the digest header.
store_digest_authorization_nonce $c, $key, $nonce
get_digest_authorization_nonce $c, $key
Set or get the $nonce object used by the digest auth mode.
You may override these methods. By default they will call "get" and "set" on $c->cache. π
authentication_failed
Sets the 401 response and calls $ctx->detach.
π CONFIGURATION π
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:
typeβ can be either"any"(the default),"basic"or"digest". This controlsauthorization_required_responseandauthenticate, but not the"manual"methods.authorization_required_messageβ set this to a string to override the default body contentAuthorization required., or set toundefto suppress body content being generated.password_typeβ the type of password returned by the user object. Same usage as inCatalyst::Authentication::Credential::Password.password_fieldβ the name of accessor used to retrieve the value of the password field from the user object. Same usage as inCatalyst::Authentication::Credential::Password.username_fieldβ the field name that the user's username is mapped into when finding the user from the realm. Defaults to'username'.use_uri_forβ if this configuration key has a true value, then the domain(s) for the authorization header will be run through$c->uri_for(). Use this if your app isn't running at the root of your domain, and you wanna make sure authentication credentials from your application are not shared with other applications on the same server. π«Άrequire_sslβ if this configuration key has a true value then authentication will be denied (and a 401 issued in normal circumstances) unless the request is via https.no_unprompted_authorization_requiredβ causes authentication to fail as normal modules do, without calling$c->detach. This means the basic auth credential can be used as part of the progressive realm.- However, using it like this is probably not optimum β it also means that users in browsers will never get an HTTP authenticate dialogue box (unless you manually return a 401 response in your application), and even some automated user agents (for APIs) won't send the
Authorizationheader without specific manipulation of the request headers. π
- However, using it like this is probably not optimum β it also means that users in browsers will never get an HTTP authenticate dialogue box (unless you manually return a 401 response in your application), and even some automated user agents (for APIs) won't send the
broken_dotnet_digest_without_query_stringβ enables support for .NET (or other similarly broken clients), which fails to include the query string in the uri in the digestAuthorizationheader, contrary to rfc2617. This option has no effect on clients that do include the query string; they'll keep working as normal. (pandering to the broken clients, we love to see it π)
π§ 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 with Catalyst::Authentication::Store::Htpasswd, or Catalyst::Authentication::Store::DBIC stores whose "password" methods return a hashed or salted version of the password. so if your store hashes, digest is a no-go, no cap. π
π§ SEE ALSO π§
RFC 2617 (or its successors), Catalyst::Plugin::Cache, Catalyst::Plugin::Authentication
π SUPPORT π
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's also a mailing list available for users of this distribution, at <http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst>.
There's also an irc channel available for users of this distribution, at #catalyst on irc.perl.org <irc://irc.perl.org/#catalyst>. π
β AUTHOR β
ΧΧΧΧ Χ§ΧΧ'ΧΧ (Yuval Kogman) <nothingmuch@woobling.org>
π CONTRIBUTORS π
- Tomas Doran <bobtfish@bobtfish.net>
- Karen Etheridge <ether@cpan.org>
- Sascha Kiefer <esskar@cpan.org>
- Alexander Hartmaier <abraxxa@cpan.org>
- Devin Austin <devin.austin@gmail.com>
- Jess Robinson <cpan@desert-island.me.uk>
- Ronald J Kimball <rjk@linguist.dartmouth.edu>
- Ronald J Kimball <rjk@tamias.net>
- Tomas Doran <tdoran@yelp.com>
- Ton Voon <ton.voon@opsera.com>
- Brian Cassidy <bricas@cpan.org>
- Graham Knop <haarg@haarg.org>
- Jonathan Rockway <jon@jrock.us>
- J. Shirley <jshirley+cpan@gmail.com>
- Robert Rothenberg <rrwo@cpan.org>
and that's a wrap on part 1 bestie β more is coming, don't go anywhere π β¨
π COPYRIGHT AND LICENCE π
Okay bestie, legal bit, but make it cute. β¨
This software is copyright (c) 2006 by ΧΧΧΧ Χ§ΧΧ'ΧΧ (Yuval Kogman). π
And likeβ¦ it's free software π¦ β you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. That's the whole vibe. No cap, that's genuinely it.
No sneaky extra rules hiding in a footnote, no "actually you also owe us your firstborn" clause. Just Perl terms, same as always. Slay. π
And that's the whole page, bestie!! π You just read the perl v5.40.1 edition, dated 2025-10-27 β go forth and HTTP responsibly. π«Ά byeee π
π¦ where this page comes from
- ubuntu resolute: libcatalyst-authentication-credential-http-perl 1.019-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libcatalyst-authentication-credential-http-perl 1.019-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms