Dancer::Plugin::Auth::Htpasswd - Basic HTTP authentication with htpasswd files in Dancer apps
version 0.020
Dancer::Plugin::Auth::Htpasswd allows you to use Apache-style htpasswd files to implement basic HTTP authentication in Dancer web applications.
Add the plugin to your application:
use Dancer::Plugin::Auth::Htpasswd;
In the configuration file, list the paths that you want to protect and the htpasswd files to use:
plugins: "Auth::Htpasswd": paths: "/restricted": /path/to/htpasswd "/secret/documents": realm: "Top Secret Documents" passwd_file: /different/path/to/htpasswd
You can also enable authentication by calling the auth_htpasswd function in a before filter:
auth_htpasswd
before sub { auth_htpasswd realm => 'Secret Files', passwd_file => '/path/to/htpasswd'; };
or in a route handler:
get '/restricted' => sub { auth_htpasswd '/path/to/htpasswd'; # Authenticated ... };
Dancer::Plugin::Auth::Htpasswd provides a simple way to implement basic HTTP authentication in Dancer web applications using Apache-style htpasswd files.
To configure the plugin, add its options in the plugins section of your application's configuration file. The supported options are listed below.
plugins
Defines one or more paths that will be protected, including sub-paths (so if the path is "/restricted", then "/restricted/secret/file.html" will also be protected). Each path can have the following parameters:
"/restricted"
"/restricted/secret/file.html"
passwd_file
Location of the htpasswd file.
realm
Realm name that will be displayed in the authentication dialog. Default: "Restricted area"
"Restricted area"
Example:
plugins: "Auth::Htpasswd": paths: "/classified": realm: "Classified Files" passwd_file: /path/to/htpasswd
If you don't need to set the realm, you can use the simplified syntax with just the location of the htpasswd file:
plugins: "Auth::Htpasswd": paths: "/secret/documents": /path/to/htpasswd "/restricted": /another/path/to/htpasswd
Call this function in a before filter or at the beginning of a route handler. It checks the specified htpasswd file to verify if the client is authorized to access the requested path -- if not, it immediately returns a 401 Unauthorized response to prompt the user to authenticate.
You can call this function with a single parameter, which is the location of the htpasswd file to use:
auth_htpasswd '/path/to/htpasswd';
or, with a hash of parameters:
auth_htpasswd realm => 'Authorized personnel only', passwd_file => '/path/to/htpasswd';
Parameters:
Authen::Htpasswd
The plugin uses the Authen::Htpasswd module, written by David Kamholz and Yuval Kogman.
Please report any bugs or feature requests through the issue tracker at https://github.com/odyniec/p5-Dancer-Plugin-Auth-Htpasswd/issues. You will be notified automatically of any progress on your issue.
This is open source software. The code repository is available for public review and contribution under the terms of the license.
https://github.com/odyniec/p5-Dancer-Plugin-Auth-Htpasswd
git clone https://github.com/odyniec/p5-Dancer-Plugin-Auth-Htpasswd.git
Michal Wojciechowski <odyniec@cpan.org>
This software is copyright (c) 2011 by Michal Wojciechowski.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Dancer::Plugin::Auth::Htpasswd, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dancer::Plugin::Auth::Htpasswd
CPAN shell
perl -MCPAN -e shell install Dancer::Plugin::Auth::Htpasswd
For more information on module installation, please visit the detailed CPAN module installation guide.