Apache2-Authen-OdinAuth
view release on metacpan or search on metacpan
lib/Apache2/Authen/OdinAuth.pm view on Meta::CPAN
package Apache2::Authen::OdinAuth;
use 5.006;
use strict;
use warnings;
=head1 NAME
Apache2::Authen::OdinAuth - A cookie-based single sign-on module for Apache.
=head1 VERSION
Version 0.8
=cut
our $VERSION = 0.8;
use Crypt::OdinAuth;
use Apache2::Log;
use Apache2::RequestRec ();
use Apache2::RequestUtil;
use Apache2::ServerUtil ();
use Apache2::URI ();
use Apache2::Connection;
use Apache2::Const -compile => qw(OK REDIRECT REMOTE_NOLOOKUP FORBIDDEN);
use APR::Table;
use YAML::XS;
use Sys::Hostname;
=head1 SYNOPSIS
This module defines an Apache handler for the Odin Authenticator
single sign-on system. The system is based on the GodAuth script,
available at L<http://github.com/exflickr/GodAuth/>.
=head1 USAGE
To make Apache use the handler for authentication, enable mod_perl and
add following directives in apache2.conf:
PerlSetVar odinauth_config /path/to/odin_auth.yml
PerlFixupHandler Apache2::Authen::OdinAuth
The C<PerlSetVar> statement needs to be global; the
C<PerlFixupHandler> statement can be global or occur in a
C<VirtualHost>, C<Directory>, or C<Location> section.
=head2 YAML CONFIG
The handler reads (and automatically reloads if it's older than
C<reload_timeout> seconds) an additional YAML config file. It sets
configures the shared secret, cookie name, authorizer app URL, and
permissions (which are unfortunately regexp-based).
A sample configuration file looks like this:
# Sample config for Apache2::Authen::OdinAuth
permissions:
# URLs no auth
- url: !!perl/regexp ^localhost
who: all
# Require a role
- url: !!perl/regexp ^dev\.myapp\.com
who: role:admin
# Require username
- url: !!perl/regexp ^debug\.myapp\.com/
who: cal
# A list is fine too
- url: !!perl/regexp ^debug2\.myapp\.com/
who:
- role:devel
- cal
- myles
# Allow any authenticated user
- url: !!perl/regexp ^debug3\.myapp\.com/
who: authed
# log_file: /tmp/odin.log
secret: ****************
reload_timeout: 600
need_auth_url: http://example.com/?NA
invalid_cookie_url: http://example.com/?CIU
not_on_list_url: http://example.com/?NOL
cookie: oa
NOTE: The config is better than original GodAuth configuration, but
will probably need to be refactored; it would be best to make it live
inside Apache's configuration. I'm still not sure how to make it
happen in mod_perl.
=cut
use constant RELOAD_TIMEOUT => 10*60; # reload config every 10 minutes
=head1 SUBROUTINES
=head2 Configuration closure
=cut
{
my $last_reload_time = -1;
my $config_file = undef;
my $config = undef;
=head3 config
Reloads configuration if older than RELOAD_TIMEOUT
=cut
sub config {
if ( time() - $last_reload_time > RELOAD_TIMEOUT ) {
$config = YAML::XS::LoadFile($config_file);
}
( run in 2.324 seconds using v1.01-cache-2.11-cpan-788537b7465 )