view release on metacpan or search on metacpan
- Bug Fix: when copying user from prev request, check that $r->prev
is defined, not just that $r->is_initial_request is true.
Version: 3.09
- POD doc fixes.
- MP2: remove _check_request_req() - this was only necessary when
running under both MP1 and MP2. Package name change eliminates the
need for this.
- test suite converted to Test::More style test suites.
- descriptive test descriptions added
- make login() stash credentials in $r->pnotes("${AuthName}Creds") so
that the login form can access the user-supplied credentials if the
login fails.
- bug fix: use of Apache2::URI::unescape_url() does not handle
'+' to ' ' conversion. This caused problems for credentials
that contain spaces.
- MP2: remove mod_perl features from "use mod_perl2" line. This is
no longer supported by mod_perl2.
- MP2: _get_form_data() - switch to CGI.pm to handle form data (fixes
several form data handling bugs)
- In a subrequest, copy $r->prev->user to $r->user (or r->connection->user
for MP1).
- remove Apache2::AuthCookie::Util - no longer necessary
- multi-valued form fields are now handled properly in POST -> GET conversion
- MP2: require CGI.pm 3.12 or later
code in handle_cache() (Mark A. Hershberger)
- reorganized tree to support multiple mod_perl versions.
- rewrote tests to use Apache::Test framework from CPAN.
- fix POD errors in authorize() documentation.
- initial support for mod_perl version 2
- mp2: check for Apache::RequestRec arg so that unported subclasses
throw exceptions.
Version: 3.04
- add _convert_to_get() to login_form(), and make POST -> GET conversion
skip credentials and destination data so only extra data is copied. This
ensures that "destination" wont contain the login data.
Version: 3.03
- various POD typos fixed (Eric Cholet)
- Add support for ${AuthName}P3P which will set up a P3P header that will
be sent with the cookie.
- fix undefined warning in _convert_to_get (David K Trudgett)
- fix potential cookie clobbering if cookie was set in earlier handler
phase in send_cookie() (Carlyn Hicks).
- various undefined value warnings eliminated
- POST -> GET conversion was broken (r->content called twice). Fixed.
Version: 3.01
- adopted support for custom_errors() hook from michael@bizsystems.com.
- Fixed incorrect documentation in authorize() (thanks to David Young).
- login() handler changes:
o if "destination" isnt in posted data, set AuthCookieReason to
no_cookie and return to login_form (previously just returned
SERVER_ERROR).
o if authen_cred() returns false, set AuthCookieReason to
bad_credentials and return to the login form.
o try to handle POST -> GET conversion.
- CGI::Util dependency removed (these are internal subroutines for CGI.pm)
- ${AuthName}Path will default to "/" if it is not specified (MSIE 6.0
wont set cookies without path)
- fix login() handler change so that destination doesnt get lost on
subsequent login attempts (thanks Phillip Molter)
Version: 3.00
- New maintiner: Michael Schout <mschout@gkg.net>
- changed to hard coded $VERSION rather than RCS Revision style.
Added an internal _cookie_string method that helps construct cookie
strings. This shouldn't change any functionality, but makes my job
easier.
Added a couple of Makefile.PL questions that set the user & group
tests should run under.
Version: 2.001 Date: 2000/02/11 04:46:59
The login forms may now use the POST method instead of the GET method.
This is a big deal, because with GET the user's credentials get logged
to access logs, they remain in the user's browser history, and so on.
Thanks to cholet@logilune.com (Eric Cholet) for the patch and prodding.
There is now a proper test suite, which will fire up an httpd and make
requests of it. The test code is adapted from Eric's old example
(eg/) suite.
I've added a logout() method to help unset cookies. The example
logout.pl now uses logout(). Thanks to Aaron Ross
(ross@mathforum.com).
OVERVIEW
Apache::AuthCookie allows you to intercept a user's first unauthenticated
access to a protected document. The user will be presented with a custom
form where they can enter authentication credentials. The credentials are
posted to the server where AuthCookie verifies them and returns a session
key.
The session key is returned to the user's browser as a cookie. As a cookie,
the browser will pass the session key on every subsequent accesses.
AuthCookie will verify the session key and re-authenticate the user.
All you have to do is write a custom module that inherits from AuthCookie.
See the POD documentation for more details.
lib/Apache/AuthCookie.pm view on Meta::CPAN
$r->log_error("destination changed to $destination");
}
else {
$r->log_error("Returning login form: non local destination: $destination");
$r->subprocess_env('AuthCookieReason', 'no_cookie');
return $auth_type->login_form($r);
}
}
}
# Get the credentials from the data posted by the client
my @credentials;
for (my $i = 0 ; defined $params->param("credential_$i") ; $i++) {
my $key = "credential_$i";
my $val = $params->param("credential_$i");
$r->log_error("$key $val") if $debug >= 2;
push @credentials, $val;
}
# save creds in pnotes in case login form script wants to use them.
$r->pnotes("${auth_name}Creds", \@credentials);
# Exchange the credentials for a session key.
my $ses_key = $self->authen_cred($r, @credentials);
unless ($ses_key) {
$r->log_error("Bad credentials") if $debug >= 2;
$r->subprocess_env('AuthCookieReason', 'bad_credentials');
$r->uri($self->untaint_destination($destination));
return $auth_type->login_form;
}
if ($debug >= 2) {
if (defined $ses_key) {
$r->log_error("ses_key $ses_key");
}
else {
$r->log_error("ses_key undefined");
lib/Apache/AuthCookie.pm view on Meta::CPAN
AuthName WhatEver
SetHandler perl-script
PerlHandler Sample::Apache::AuthCookieHandler->login
</Files>
=head1 DESCRIPTION
B<Apache::AuthCookie> allows you to intercept a user's first
unauthenticated access to a protected document. The user will be
presented with a custom form where they can enter authentication
credentials. The credentials are posted to the server where AuthCookie
verifies them and returns a session key.
The session key is returned to the user's browser as a cookie. As a
cookie, the browser will pass the session key on every subsequent
accesses. AuthCookie will verify the session key and re-authenticate
the user.
All you have to do is write a custom module that inherits from
AuthCookie. Your module is a class which implements two methods:
=over 4
=item C<authen_cred()>
Verify the user-supplied credentials and return a session key. The
session key can be any string - often you'll use some string
containing username, timeout info, and any other information you need
to determine access to documents, and append a one-way hash of those
values together with some secret key.
=item C<authen_ses_key()>
Verify the session key (previously generated by C<authen_cred()>,
possibly during a previous request) and return the user ID. This user
ID will be fed to C<$r-E<gt>connection-E<gt>user()> to set Apache's
lib/Apache/AuthCookie.pm view on Meta::CPAN
=back
By using AuthCookie versus Apache's built-in AuthBasic you can design
your own authentication system. There are several benefits.
=over 4
=item 1.
The client doesn't *have* to pass the user credentials on every
subsequent access. If you're using passwords, this means that the
password can be sent on the first request only, and subsequent
requests don't need to send this (potentially sensitive) information.
This is known as "ticket-based" authentication.
=item 2.
When you determine that the client should stop using the
credentials/session key, the server can tell the client to delete the
cookie. Letting users "log out" is a notoriously impossible-to-solve
problem of AuthBasic.
=item 3.
AuthBasic dialog boxes are ugly. You can design your own HTML login
forms when you use AuthCookie.
=item 4.
lib/Apache/AuthCookie.pm view on Meta::CPAN
PerlSetVar WhatEverSatisfy Any
into your server startup file and authentication for this realm will succeed if
ANY of the C<require> directives are met.
=back
This is the flow of the authentication handler, less the details of the
redirects. Two REDIRECT's are used to keep the client from displaying
the user's credentials in the Location field. They don't really change
AuthCookie's model, but they do add another round-trip request to the
client.
(-----------------------) +---------------------------------+
( Request a protected ) | AuthCookie sets custom error |
( page, but user hasn't )---->| document and returns |
( authenticated (no ) | FORBIDDEN. Apache abandons |
( session key cookie) ) | current request and creates sub |
(-----------------------) | request for the error document. |<-+
| Error document is a script that | |
| generates a form where the user | |
return | enters authentication | |
^------------------->| credentials (login & password). | |
/ \ False +---------------------------------+ |
/ \ | |
/ \ | |
/ \ V |
/ \ +---------------------------------+ |
/ Pass \ | User's client submits this form | |
/ user's \ | to the LOGIN URL, which calls | |
| credentials |<------------| AuthCookie->login(). | |
\ to / +---------------------------------+ |
\authen_cred/ |
\ function/ |
\ / |
\ / |
\ / +------------------------------------+ |
\ / return | Authen cred returns a session | +--+
V------------->| key which is opaque to AuthCookie.*| |
True +------------------------------------+ |
| |
lib/Apache/AuthCookie.pm view on Meta::CPAN
username and password (similar in function to Digest
authentication), or the user name and password in plain text
(similar in function to HTTP Basic authentication).
The only requirement is that the authen_ses_key function that you
create must be able to determine if this session_key is valid and
map it back to the originally authenticated user ID.
=head1 METHODS
=head2 authen_cred($r, @credentials)
You must define this method yourself in your subclass of
C<Apache::AuthCookie>. Its job is to create the session key that will
be preserved in the user's cookie. The arguments passed to it are:
sub authen_cred ($$\@) {
my $self = shift; # Package name (same as AuthName directive)
my $r = shift; # Apache request object
my @cred = @_; # Credentials from login form
lib/Apache/AuthCookie.pm view on Meta::CPAN
the user authentication information. i.e.
/restricted
/one user is allowed access here
/two not here
/three AND here
The authen_ses_key method would return a normal response when the user attempts
to access 'one' or 'three' but return (NOT_FOUND, 'File not found') if an
attempt was made to access subdirectory 'two'. Or, in the case of expired
credentials, (AUTH_REQUIRED,'Your session has timed out, you must login
again').
example 'custom_errors'
sub custom_errors {
my ($self,$r,$CODE,$msg) = @_;
# return custom message else use the server's standard message
$r->custom_response($CODE, $msg) if $msg;
return($CODE);
}
lib/Apache/AuthCookie.pm view on Meta::CPAN
=head2 params($r): Apache::AuthCookie::Params
Get the params object for this request.
=head2 login($r)
This method handles the submission of the login form. It will call
the C<authen_cred()> method, passing it C<$r> and all the submitted
data with names like C<"credential_#">, where # is a number. These will
be passed in a simple array, so the prototype is
C<$self-E<gt>authen_cred($r, @credentials)>. After calling
C<authen_cred()>, we set the user's cookie and redirect to the
URL contained in the C<"destination"> submitted form field.
=head2 untaint_destination($uri)
This method returns a modified version of the destination parameter
before embedding it into the response header. Per default it escapes
CR, LF and TAB characters of the uri to avoid certain types of
security attacks. You can override it to more limit the allowed
destinations, e.g., only allow relative uris, only special hosts or
lib/Apache/AuthCookie.pm view on Meta::CPAN
You must define a form field called 'destination' that tells
AuthCookie where to redirect the request after successfully logging
in. Typically this value is obtained from C<$r-E<gt>prev-E<gt>uri>.
See the login.pl script in t/eg/.
=back
In addition, you might want your login page to be able to tell why
the user is being asked to log in. In other words, if the user sent
bad credentials, then it might be useful to display an error message
saying that the given username or password are invalid. Also, it
might be useful to determine the difference between a user that sent
an invalid auth cookie, and a user that sent no auth cookie at all. To
cope with these situations, B<AuthCookie> will set
C<$r-E<gt>subprocess_env('AuthCookieReason')> to one of the following values.
=over 4
=item I<no_cookie>
The user presented no cookie at all. Typically this means the user is
trying to log in for the first time.
=item I<bad_cookie>
The cookie the user presented is invalid. Typically this means that the user
is not allowed access to the given page.
=item I<bad_credentials>
The user tried to log in, but the credentials that were passed are invalid.
=back
You can examine this value in your login form by examining
C<$r-E<gt>prev-E<gt>subprocess_env('AuthCookieReason')> (because it's
a sub-request).
Of course, if you want to give more specific information about why
access failed when a cookie is present, your C<authen_ses_key()>
method can set arbitrary entries in C<$r-E<gt>subprocess_env>.
lib/Apache2/AuthCookie.pm view on Meta::CPAN
</Files>
=head1 DESCRIPTION
This module is for mod_perl version 2. If you are running mod_perl version 1,
you should be using B<Apache::AuthCookie> instead.
B<Apache2::AuthCookie> allows you to intercept a user's first
unauthenticated access to a protected document. The user will be
presented with a custom form where they can enter authentication
credentials. The credentials are posted to the server where AuthCookie
verifies them and returns a session key.
The session key is returned to the user's browser as a cookie. As a
cookie, the browser will pass the session key on every subsequent
accesses. AuthCookie will verify the session key and re-authenticate
the user.
All you have to do is write a custom module that inherits from
AuthCookie. Your module is a class which implements two methods:
=over 4
=item C<authen_cred()>
Verify the user-supplied credentials and return a session key. The
session key can be any string - often you'll use some string
containing username, timeout info, and any other information you need
to determine access to documents, and append a one-way hash of those
values together with some secret key.
=item C<authen_ses_key()>
Verify the session key (previously generated by C<authen_cred()>,
possibly during a previous request) and return the user ID. This user
ID will be fed to C<$r-E<gt>user()> to set Apache's idea of who's logged in.
=back
By using AuthCookie versus Apache's built-in AuthBasic you can design
your own authentication system. There are several benefits.
=over 4
=item 1.
The client doesn't *have* to pass the user credentials on every
subsequent access. If you're using passwords, this means that the
password can be sent on the first request only, and subsequent
requests don't need to send this (potentially sensitive) information.
This is known as "ticket-based" authentication.
=item 2.
When you determine that the client should stop using the
credentials/session key, the server can tell the client to delete the
cookie. Letting users "log out" is a notoriously impossible-to-solve
problem of AuthBasic.
=item 3.
AuthBasic dialog boxes are ugly. You can design your own HTML login
forms when you use AuthCookie.
=item 4.
lib/Apache2/AuthCookie.pm view on Meta::CPAN
PerlSetVar WhatEverSatisfy Any
into your server startup file and authentication for this realm will succeed if
ANY of the C<require> directives are met.
=back
This is the flow of the authentication handler, less the details of the
redirects. Two HTTP_MOVED_TEMPORARILY's are used to keep the client from
displaying the user's credentials in the Location field. They don't really
change AuthCookie's model, but they do add another round-trip request to the
client.
(-----------------------) +---------------------------------+
( Request a protected ) | AuthCookie sets custom error |
( page, but user hasn't )---->| document and returns |
( authenticated (no ) | HTTP_FORBIDDEN. Apache abandons |
( session key cookie) ) | current request and creates sub |
(-----------------------) | request for the error document. |<-+
| Error document is a script that | |
| generates a form where the user | |
return | enters authentication | |
^------------------->| credentials (login & password). | |
/ \ False +---------------------------------+ |
/ \ | |
/ \ | |
/ \ V |
/ \ +---------------------------------+ |
/ Pass \ | User's client submits this form | |
/ user's \ | to the LOGIN URL, which calls | |
| credentials |<------------| AuthCookie->login(). | |
\ to / +---------------------------------+ |
\authen_cred/ |
\ function/ |
\ / |
\ / |
\ / +------------------------------------+ |
\ / return | Authen cred returns a session | +--+
V------------->| key which is opaque to AuthCookie.*| |
True +------------------------------------+ |
| |
lib/Apache2/AuthCookie.pm view on Meta::CPAN
the user authentication information. i.e.
/restricted
/one user is allowed access here
/two not here
/three AND here
The authen_ses_key method would return a normal response when the user attempts
to access 'one' or 'three' but return (NOT_FOUND, 'File not found') if an
attempt was made to access subdirectory 'two'. Or, in the case of expired
credentials, (AUTH_REQUIRED,'Your session has timed out, you must login
again').
example 'custom_errors'
sub custom_errors {
my ($self,$r,$CODE,$msg) = @_;
# return custom message else use the server's standard message
$r->custom_response($CODE, $msg) if $msg;
return($CODE);
}
lib/Apache2/AuthCookie.pm view on Meta::CPAN
You must define a form field called 'destination' that tells
AuthCookie where to redirect the request after successfully logging
in. Typically this value is obtained from C<$r-E<gt>prev-E<gt>uri>.
See the login.pl script in t/eg/.
=back
In addition, you might want your login page to be able to tell why
the user is being asked to log in. In other words, if the user sent
bad credentials, then it might be useful to display an error message
saying that the given username or password are invalid. Also, it
might be useful to determine the difference between a user that sent
an invalid auth cookie, and a user that sent no auth cookie at all. To
cope with these situations, B<AuthCookie> will set
C<$r-E<gt>subprocess_env('AuthCookieReason')> to one of the following values.
=over 4
=item I<no_cookie>
The user presented no cookie at all. Typically this means the user is
trying to log in for the first time.
=item I<bad_cookie>
The cookie the user presented is invalid. Typically this means that the user
is not allowed access to the given page.
=item I<bad_credentials>
The user tried to log in, but the credentials that were passed are invalid.
=back
You can examine this value in your login form by examining
C<$r-E<gt>prev-E<gt>subprocess_env('AuthCookieReason')> (because it's
a sub-request).
Of course, if you want to give more specific information about why
access failed when a cookie is present, your C<authen_ses_key()>
method can set arbitrary entries in C<$r-E<gt>subprocess_env>.
lib/Apache2/AuthCookie/Base.pm view on Meta::CPAN
$r->server->log_error("destination changed to $destination");
}
else {
$r->server->log_error("Returning login form: non local destination: $destination");
$r->subprocess_env('AuthCookieReason', 'no_cookie');
return $auth_type->login_form($r);
}
}
}
# Get the credentials from the data posted by the client
my @credentials;
for (my $i = 0; defined $params->param("credential_$i"); $i++) {
my $key = "credential_$i";
my $val = $params->param($key);
$r->server->log_error("$key $val") if $debug >= 2;
push @credentials, $val;
}
# save creds in pnotes so login form script can use them if it wants to
$r->pnotes("${auth_name}Creds", \@credentials);
# Exchange the credentials for a session key.
my $ses_key = $self->authen_cred($r, @credentials);
unless ($ses_key) {
$r->server->log_error("Bad credentials") if $debug >= 2;
$r->subprocess_env('AuthCookieReason', 'bad_credentials');
$r->uri($self->untaint_destination($destination));
return $auth_type->login_form($r);
}
if ($debug >= 2) {
defined $ses_key ? $r->server->log_error("ses_key $ses_key")
: $r->server->log_error("ses_key undefined");
}
$self->send_cookie($r, $ses_key);
lib/Apache2/AuthCookie/Base.pm view on Meta::CPAN
This method will return the current session key, if any. This can be handy
inside a method that implements a C<require> directive check (like the
C<species> method discussed above) if you put any extra information like
clearances or whatever into the session key.
=head2 login($r): int
This method handles the submission of the login form. It will call the
C<authen_cred()> method, passing it C<$r> and all the submitted data with names
like C<credential_#>, where # is a number. These will be passed in a simple
array, so the prototype is C<$self-E<gt>authen_cred($r, @credentials)>. After
calling C<authen_cred()>, we set the user's cookie and redirect to the URL
contained in the C<destination> submitted form field.
=head2 login_form($r): int
This method is responsible for displaying the login form. The default
implementation will make an internal redirect and display the URL you specified
with the C<PerlSetVar WhatEverLoginScript> configuration directive. You can
overwrite this method to provide your own mechanism.
lib/Apache2_4/AuthCookie.pm view on Meta::CPAN
</Files>
=head1 DESCRIPTION
This module is for C<mod_perl> version 2 for C<Apache> version 2.4.x. If you
are running mod_perl version 1, you need B<Apache::AuthCookie> instead. If you
are running C<Apache> 2.0.0-2.2.x, you need B<Apache2::AuthCookie> instead.
B<Apache2_4::AuthCookie> allows you to intercept a user's first unauthenticated
access to a protected document. The user will be presented with a custom form
where they can enter authentication credentials. The credentials are posted to
the server where AuthCookie verifies them and returns a session key.
The session key is returned to the user's browser as a cookie. As a cookie, the
browser will pass the session key on every subsequent accesses. AuthCookie will
verify the session key and re-authenticate the user.
All you have to do is write a custom module that inherits from AuthCookie.
Your module is a class which implements two methods:
=over 4
=item C<authen_cred()>
Verify the user-supplied credentials and return a session key. The session key
can be any string - often you'll use some string containing username, timeout
info, and any other information you need to determine access to documents, and
append a one-way hash of those values together with some secret key.
=item C<authen_ses_key()>
Verify the session key (previously generated by C<authen_cred()>, possibly
during a previous request) and return the user ID. This user ID will be fed to
C<$r-E<gt>user()> to set Apache's idea of who's logged in.
=back
By using AuthCookie versus Apache's built-in AuthBasic you can design your own
authentication system. There are several benefits.
=over 4
=item 1.
The client doesn't *have* to pass the user credentials on every subsequent
access. If you're using passwords, this means that the password can be sent on
the first request only, and subsequent requests don't need to send this
(potentially sensitive) information. This is known as "ticket-based"
authentication.
=item 2.
When you determine that the client should stop using the credentials/session
key, the server can tell the client to delete the cookie. Letting users "log
out" is a notoriously impossible-to-solve problem of AuthBasic.
=item 3.
AuthBasic dialog boxes are ugly. You can design your own HTML login forms when
you use AuthCookie.
=item 4.
lib/Apache2_4/AuthCookie.pm view on Meta::CPAN
PerlSetVar WhatEverCookieName MyCustomName
into your server setup file and your cookies for this AuthCookie realm will be
named MyCustomName. Default is AuthType_AuthName.
=back
This is the flow of the authentication handler, less the details of the
redirects. Two HTTP_MOVED_TEMPORARILY's are used to keep the client from
displaying the user's credentials in the Location field. They don't really
change AuthCookie's model, but they do add another round-trip request to the
client.
(-----------------------) +---------------------------------+
( Request a protected ) | AuthCookie sets custom error |
( page, but user hasn't )---->| document and returns |
( authenticated (no ) | HTTP_FORBIDDEN. Apache abandons |
( session key cookie) ) | current request and creates sub |
(-----------------------) | request for the error document. |<-+
| Error document is a script that | |
| generates a form where the user | |
return | enters authentication | |
^------------------->| credentials (login & password). | |
/ \ False +---------------------------------+ |
/ \ | |
/ \ | |
/ \ V |
/ \ +---------------------------------+ |
/ Pass \ | User's client submits this form | |
/ user's \ | to the LOGIN URL, which calls | |
| credentials |<------------| AuthCookie->login(). | |
\ to / +---------------------------------+ |
\authen_cred/ |
\ function/ |
\ / |
\ / |
\ / +------------------------------------+ |
\ / return | Authen cred returns a session | +--+
V------------->| key which is opaque to AuthCookie.*| |
True +------------------------------------+ |
| |
lib/Apache2_4/AuthCookie.pm view on Meta::CPAN
the user authentication information. i.e.
/restricted
/one user is allowed access here
/two not here
/three AND here
The authen_ses_key method would return a normal response when the user attempts
to access 'one' or 'three' but return (NOT_FOUND, 'File not found') if an
attempt was made to access subdirectory 'two'. Or, in the case of expired
credentials, (AUTH_REQUIRED,'Your session has timed out, you must login
again').
example 'custom_errors'
sub custom_errors {
my ($self,$r,$CODE,$msg) = @_;
# return custom message else use the server's standard message
$r->custom_response($CODE, $msg) if $msg;
lib/Apache2_4/AuthCookie.pm view on Meta::CPAN
=item 3.
You must define a form field called 'destination' that tells AuthCookie where
to redirect the request after successfully logging in. Typically this value is
obtained from C<$r-E<gt>prev-E<gt>uri>. See the login.pl script in t/eg/.
=back
In addition, you might want your login page to be able to tell why the user is
being asked to log in. In other words, if the user sent bad credentials, then
it might be useful to display an error message saying that the given username
or password are invalid. Also, it might be useful to determine the difference
between a user that sent an invalid auth cookie, and a user that sent no auth
cookie at all. To cope with these situations, B<AuthCookie> will set
C<$r-E<gt>subprocess_env('AuthCookieReason')> to one of the following values.
=over 4
=item I<no_cookie>
The user presented no cookie at all. Typically this means the user is
trying to log in for the first time.
=item I<bad_cookie>
The cookie the user presented is invalid. Typically this means that the user
is not allowed access to the given page.
=item I<bad_credentials>
The user tried to log in, but the credentials that were passed are invalid.
=back
You can examine this value in your login form by examining
C<$r-E<gt>prev-E<gt>subprocess_env('AuthCookieReason')> (because it's a
sub-request).
Of course, if you want to give more specific information about why access
failed when a cookie is present, your C<authen_ses_key()> method can set
arbitrary entries in C<$r-E<gt>subprocess_env>.
t/Skeleton/AuthCookieHandler.pm view on Meta::CPAN
use vars qw($VERSION @ISA);
$VERSION = substr(q$Revision$, 10);
@ISA = qw(Apache::AuthCookie);
sub authen_cred ($$\@) {
my $self = shift;
my $r = shift;
my @creds = @_;
# This would really authenticate the credentials
# and return the session key.
# Here I'm just using setting the session
# key to the credentials and delaying authentication.
#
# Similar to HTTP Basic Authentication, only not base 64 encoded
join(":", @creds);
}
sub authen_ses_key ($$$) {
my $self = shift;
my $r = shift;
my($user, $password) = split(/:/, shift, 2);
t/lib/Sample/Apache/AuthCookieHandler.pm view on Meta::CPAN
use Apache::AuthCookie;
use Apache::Util;
use URI::Escape qw(uri_escape_utf8 uri_unescape);
use Encode;
sub authen_cred ($$\@) {
my $self = shift;
my $r = shift;
my @creds = @_;
return if $creds[0] eq 'fail'; # simulate bad_credentials
# This would really authenticate the credentials
# and return the session key.
# Here I'm just using setting the session
# key to the escaped credentials and delaying authentication.
return join ':', map { uri_escape_utf8($_) } @creds;
}
sub authen_ses_key ($$$) {
my ($self, $r, $ses_key) = @_;
# NOTE: uri_escape_utf8() was used to encode this so we have to decode
# using UTF-8. We don't rely on $self->encoding($r) here because if an
# encoding other than UTF-8 is configured in t/conf/extra.conf.in, then the
# wrong encoding gets used here.
t/lib/Sample/Apache2/AuthCookieHandler.pm view on Meta::CPAN
@ISA = qw(Apache2::AuthCookie);
}
sub authen_cred ($$\@) {
my $self = shift;
my $r = shift;
my @creds = @_;
$r->server->log_error("authen_cred entry");
return if $creds[0] eq 'fail'; # simulate bad_credentials
# This would really authenticate the credentials
# and return the session key.
# Here I'm just using setting the session
# key to the escaped credentials and delaying authentication.
return join ':', map { uri_escape_utf8($_) } @creds;
}
sub authen_ses_key ($$$) {
my ($self, $r, $cookie) = @_;
my ($user, $password) =
map { decode('UTF-8', uri_unescape($_)) }
split /:/, $cookie, 2;
plan tests => 1;
my $data = GET_BODY(
'/docs/protected/get_me.html',
Cookie=>'Sample::AuthCookieHandler_WhatEver=programmer:Heroo'
);
like($data, qr/Failure reason: 'bad_cookie'/, 'invalid cookie');
};
# should get the login form back (bad_credentials)
subtest 'bad credentials' => sub {
plan tests => 1;
my $r = POST('/LOGIN', [
destination => '/docs/protected/get_me.html',
credential_0 => 'fail',
credential_1 => 'Hero'
]);
like($r->content, qr/Failure reason: 'bad_credentials'/,
'invalid credentials');
};
subtest 'AuthAny' => sub {
plan tests => 3;
my $r = POST('/LOGIN', [
destination => '/docs/authany/get_me.html',
credential_0 => 'some-user',
credential_1 => 'mypassword'
]);
my $r = GET(
'/docs/stimeout/get_me.html',
Cookie => 'Sample::AuthCookieHandler_WhatEver=programmer:Hero'
);
like($r->header('Set-Cookie'),
qr/^Sample::AuthCookieHandler_WhatEver=.*expires=.+/,
'Set-Cookie contains expires property');
};
# should return bad credentials page, and credentials should be in a comment.
# We are checking here that $r->prev->pnotes('WhatEverCreds') works.
subtest 'creds are in pnotes' => sub {
plan tests => 1;
my $r = POST('/LOGIN', [
destination => '/docs/protected/get_me.html',
credential_0 => 'fail',
credential_1 => 'Hero'
]);