summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2010-09-18 15:07:38 -0500
committerJesse Luehrs <doy@tozt.net>2010-09-18 15:07:38 -0500
commit480b15b385a59784470365bef6356f55984a5644 (patch)
tree20bba7aefa9d85551b977ec28cce34cf863c0816
parent2ea2cf3a4f4888b64836758b8939d15b9b582a15 (diff)
downloadplack-middleware-auth-htpasswd-480b15b385a59784470365bef6356f55984a5644.tar.gz
plack-middleware-auth-htpasswd-480b15b385a59784470365bef6356f55984a5644.zip
make this just a subclass of ::Auth::Basic
-rw-r--r--dist.ini2
-rw-r--r--lib/Plack/Middleware/Auth/Htpasswd.pm46
2 files changed, 6 insertions, 42 deletions
diff --git a/dist.ini b/dist.ini
index ec8cec5..1b2dccf 100644
--- a/dist.ini
+++ b/dist.ini
@@ -12,4 +12,4 @@ PruneCruft_except = t/data/02
Authen::Htpasswd = 0
MIME::Base64 = 0
Path::Class = 0
-Plack = 0
+Plack = 0.9949
diff --git a/lib/Plack/Middleware/Auth/Htpasswd.pm b/lib/Plack/Middleware/Auth/Htpasswd.pm
index 447ddde..46758e6 100644
--- a/lib/Plack/Middleware/Auth/Htpasswd.pm
+++ b/lib/Plack/Middleware/Auth/Htpasswd.pm
@@ -1,8 +1,8 @@
package Plack::Middleware::Auth::Htpasswd;
use strict;
use warnings;
-use base 'Plack::Middleware';
-use Plack::Util::Accessor qw(realm file file_root);
+use base 'Plack::Middleware::Auth::Basic';
+use Plack::Util::Accessor qw(file file_root);
use Plack::Request;
use Authen::Htpasswd;
@@ -62,29 +62,10 @@ Realm name to display in the basic authentication dialog. Defaults to
sub prepare_app {
my $self = shift;
+ $self->authenticator(sub { $self->authenticate(@_) });
die "must specify either file or file_root"
unless defined $self->file || $self->file_root;
-}
-
-sub call {
- my($self, $env) = @_;
- my $auth = $env->{HTTP_AUTHORIZATION};
- return $self->unauthorized
- unless $auth && $auth =~ /^Basic (.*)$/;
-
- my $auth_string = $1;
- my ($user, $pass) = split /:/, (
- MIME::Base64::decode($auth_string . '==') || ":"
- );
- $pass = '' unless defined $pass;
-
- if ($self->authenticate($env, $user, $pass)) {
- $env->{REMOTE_USER} = $user;
- return $self->app->($env);
- }
- else {
- return $self->unauthorized;
- }
+ return $self->SUPER::prepare_app;
}
sub _check_password {
@@ -98,7 +79,7 @@ sub _check_password {
sub authenticate {
my $self = shift;
- my ($env, $user, $pass) = @_;
+ my ($user, $pass, $env) = @_;
return $self->_check_password($self->file, $user, $pass)
if defined $self->file;
@@ -120,22 +101,6 @@ sub authenticate {
return;
}
-sub unauthorized {
- my $self = shift;
- my $body = 'Authorization required';
- return [
- 401,
- [
- 'Content-Type' => 'text/plain',
- 'Content-Length' => length $body,
- 'WWW-Authenticate' => 'Basic realm="'
- . ($self->realm || "restricted area")
- . '"'
- ],
- [ $body ],
- ];
-}
-
=head1 SEE ALSO
L<Plack>
@@ -149,7 +114,6 @@ L<Plack::Middleware::Auth::Basic> by Tatsuhiko Miyagawa.
=begin Pod::Coverage
- unauthorized
authenticate
=end Pod::Coverage