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.06";
13 __PACKAGE__->mk_accessors(qw/
20 my $type = $self->type || 'basic';
22 if (!$self->_config->{url}) {
23 Catalyst::Exception->throw(__PACKAGE__ . " configuration does not include a 'url' key, cannot proceed");
26 if (!grep /^$type$/, ('basic')) {
27 Catalyst::Exception->throw(__PACKAGE__ . " used with unsupported authentication type: " . $type);
32 sub authenticate_basic {
33 my ( $self, $c, $realm, $auth_info ) = @_;
35 $c->log->debug('Checking http basic authentication.') if $c->debug;
37 my $headers = $c->req->headers;
39 if ( my ( $user, $password ) = $headers->authorization_basic ) {
40 my $ua = Catalyst::Authentication::Credential::HTTP::Proxy::User->new;
41 $ua->credentials($user, $password);
42 my $resp = $ua->get($self->url);
43 if ( $resp->is_success ) {
44 # Config username_field TODO
45 my $user_obj = $realm->find_user( { username => $user }, $c);
47 $c->log->debug("User '$user' doesn't exist in the default store")
51 $c->set_authenticated($user_obj);
55 $c->log->info('Remote authentication failed:'.$resp->message);
60 $c->log->info('No credentials provided for basic auth');
73 Catalyst::Authentication::Credential::HTTP::Proxy - HTTP Proxy authentication
82 $c->config( authentication => {
86 class => 'HTTP::Proxy',
87 type => 'basic', # Only basic supported
88 url => 'http://elkland.no/auth',
101 my ( $self, $c ) = @_;
105 # either user gets authenticated or 401 is sent
112 This module lets you use HTTP Proxy authentication with
113 L<Catalyst::Plugin::Authentication>.
115 Currently this module only supports the Basic scheme, but upon request Digest
116 will also be added. Patches welcome!
120 All configuration is stored in C<< YourApp->config(authentication => { yourrealm => { credential => { class => 'HTTP::Proxy', %config } } } >>.
122 This should be a hash, and it can contain the following entries:
128 Required. A url protected with basic authentication to authenticate against.
132 Must be either C<basic> or not present (then it defaults to C<basic>).
134 This will be used to support digest authentication in future.
144 Initializes the configuration.
146 =item authenticate_basic
148 Looks inside C<< $c->request->headers >> and processes the basic (badly named)
149 authorization header. Then authenticates this against the provided url.
155 Marcus Ramberg <mramberg@cpan.org>
157 Tomas Doran <bobtfish@bobtfish.net>
159 =head1 COPYRIGHT & LICENSE
161 Copyright (c) 2005-2008 the aforementioned authors. All rights
162 reserved. This program is free software; you can redistribute
163 it and/or modify it under the same terms as Perl itself.