From 480b15b385a59784470365bef6356f55984a5644 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 18 Sep 2010 15:07:38 -0500 Subject: make this just a subclass of ::Auth::Basic --- dist.ini | 2 +- lib/Plack/Middleware/Auth/Htpasswd.pm | 46 ++++------------------------------- 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 @@ -149,7 +114,6 @@ L by Tatsuhiko Miyagawa. =begin Pod::Coverage - unauthorized authenticate =end Pod::Coverage -- cgit v1.2.3