package Moxy::Plugin::Status::401; use strict; use warnings; use base qw/Moxy::Plugin/; use URI::Escape 'uri_unescape'; sub status_handler : Hook { my ( $self, $context, $args ) = @_; my $response = $args->{response}; if ( $response->code eq 401 ) { my $host = $response->request->header('Host'); my $referer = $response->request->uri; $response->code(200); $response->content( qq{ you need a authentication

you should input the authentication info

id
pw
} ); } } sub url_handle : Hook { my ( $self, $context, $args ) = @_; if ( $args->{request}->uri =~ m{^http://basicauth\.moxy/(.+)} ) { my $back = uri_unescape($1); my $r = CGI->new( $args->{request}->content ); # store to user stash. my $key = join( ',', __PACKAGE__, $r->param('host') ); $args->{session} ->set( $key => $r->param('id') . ':' . $r->param('pw') ); my $response = HTTP::Response->new( 302, 'Moxy(BasicAuth)' ); $response->header( Location => $back ); $response; } } sub request_filter : Hook { my ( $self, $context, $args ) = @_; my $key = join( ',', __PACKAGE__, $args->{request}->header('Host') ); my $idpw = $args->{session}->get($key); if ($idpw) { $context->log( 'debug' => "your user id:pw is $idpw" ); $args->{request}->authorization_basic(split /:/, $idpw); } } 1; __END__ =head1 NAME Moxy::Plugin::BasicAuth - basic auth =head1 DESCRIPTION basic auth handler for moxy. This plugin is a part of default plugins.This plugin load automatically :) =head1 AUTHOR tokuhirom =head1 SEE ALSO L