1 package Catalyst::Authentication::Credential::HTTP::Proxy;
2 use base qw/Catalyst::Authentication::Credential::HTTP/;
9 use Catalyst::Authentication::Credential::HTTP::Proxy::User;
11 our $VERSION = "0.04";
16 my $type = $self->_config->{'type'} ||= 'basic';
18 if (!$self->_config->{url}) {
19 Catalyst::Exception->throw(__PACKAGE__ . " configuration does not include a 'url' key, cannot proceed");
22 if (!grep /^$type$/, ('basic')) {
23 Catalyst::Exception->throw(__PACKAGE__ . " used with unsupported authentication type: " . $type);
27 sub authenticate_basic {
28 my ( $self, $c, $realm, $auth_info ) = @_;
30 $c->log->debug('Checking http basic authentication.') if $c->debug;
32 my $headers = $c->req->headers;
34 if ( my ( $user, $password ) = $headers->authorization_basic ) {
35 my $ua = Catalyst::Authentication::Credential::HTTP::Proxy::User->new;
36 $ua->credentials($user, $password);
37 my $resp = $ua->get($self->_config->{url});
38 if ( $resp->is_success ) {
39 # Config username_field TODO
40 my $user_obj = $realm->find_user( { username => $user }, $c);
42 $c->log->debug("User '$user' doesn't exist in the default store")
46 $c->set_authenticated($user_obj);
50 $c->log->info('Remote authentication failed:'.$resp->message);
55 $c->log->info('No credentials provided for basic auth');
66 Catalyst::Authentication::Credential::HTTP::Proxy - HTTP Proxy authentication
75 $c->config( authentication => {
79 class => 'HTTP::Proxy',
80 type => 'basic', # Only basic supported
81 url => 'http://elkland.no/auth',
87 Mufasa => { password => "Circle Of Life", },
94 my ( $self, $c ) = @_;
98 # either user gets authenticated or 401 is sent
105 This moduule lets you use HTTP Proxy authentication with
106 L<Catalyst::Plugin::Authentication>.
108 Currently this module only supports the Basic scheme, but upon request Digest
109 will also be added. Patches welcome!
113 All configuration is stored in C<< YourApp->config(authentication => { yourrealm => { credential => { class => 'HTTP::Proxy', %config } } } >>.
115 This should be a hash, and it can contain the following entries:
121 Required. A url protected with basic authentication to authenticate against.
125 Must be either C<basic> or not present (then it defaults to C<basic>).
127 This will be used to support digest authentication in future.
137 Initializes the configuration.
139 =item authenticate_basic
141 Looks inside C<< $c->request->headers >> and processes the basic (badly named)
142 authorization header. Then authenticates this against the provided url.
148 Marcus Ramberg <mramberg@cpan.org>
150 Tomas Doran <bobtfish@bobtfish.net>
152 =head1 COPYRIGHT & LICENSE
154 Copyright (c) 2005-2008 the aforementioned authors. All rights
155 reserved. This program is free software; you can redistribute
156 it and/or modify it under the same terms as Perl itself.