package Catalyst::Authentication::Credential::OpenID;
use strict;
-# use warnings; no warnings "uninitialized"; # for testing, not production
-use parent "Class::Accessor::Fast";
-
-BEGIN {
- __PACKAGE__->mk_accessors(qw/ _config realm debug secret /);
-}
-
-our $VERSION = "0.14_03";
+use warnings;
+use base "Class::Accessor::Fast";
+
+__PACKAGE__->mk_accessors(qw/
+ realm debug secret
+ openid_field
+ consumer_secret
+ ua_class
+ ua_args
+ extension_args
+ errors_are_fatal
+ extensions
+/);
+
+our $VERSION = "0.16";
use Net::OpenID::Consumer;
use Catalyst::Exception ();
-sub new : method {
+sub new {
my ( $class, $config, $c, $realm ) = @_;
- my $self = { _config => { %{ $config },
- %{ $realm->{config} }
- }
+ my $self = {
+ %{ $config },
+ %{ $realm->{config} }
};
bless $self, $class;
# 2.0 spec says "SHOULD" be named "openid_identifier."
- $self->_config->{openid_field} ||= "openid_identifier";
-
- $self->debug( $self->_config->{debug} );
+ $self->{openid_field} ||= "openid_identifier";
- my $secret = $self->_config->{consumer_secret} ||= join("+",
+ my $secret = $self->{consumer_secret} ||= join("+",
__PACKAGE__,
$VERSION,
sort keys %{ $c->config }
$secret = substr($secret,0,255) if length $secret > 255;
$self->secret($secret);
# If user has no preference we prefer L::PA b/c it can prevent DoS attacks.
- $self->_config->{ua_class} ||= eval "use LWPx::ParanoidAgent" ?
+ my $ua_class = $self->{ua_class} ||= eval "use LWPx::ParanoidAgent" ?
"LWPx::ParanoidAgent" : "LWP::UserAgent";
- my $agent_class = $self->_config->{ua_class};
+ my $agent_class = $self->ua_class;
eval "require $agent_class"
or Catalyst::Exception->throw("Could not 'require' user agent class " .
- $self->_config->{ua_class});
+ $self->ua_class);
$c->log->debug("Setting consumer secret: " . $secret) if $self->debug;
return $self;
}
-sub authenticate : method {
+sub authenticate {
my ( $self, $c, $realm, $authinfo ) = @_;
$c->log->debug("authenticate() called from " . $c->request->uri) if $self->debug;
- my $field = $self->{_config}->{openid_field};
+ my $field = $self->openid_field;
my $claimed_uri = $authinfo->{ $field };
$claimed_uri ||= $c->req->method eq 'GET' ?
$c->req->query_params->{ $field } : $c->req->body_params->{ $field };
+
my $csr = Net::OpenID::Consumer->new(
- ua => $self->_config->{ua_class}->new(%{$self->_config->{ua_args} || {}}),
+ ua => $self->ua_class->new(%{$self->ua_args || {}}),
args => $c->req->params,
consumer_secret => $self->secret,
);
- my @extensions = $self->_config->{extensions} ?
- @{ $self->_config->{extensions} } : $self->_config->{extension_args} ?
- @{ $self->_config->{extension_args} } : ();
+ if ( $self->extension_args and $self->debug )
+ {
+ # FIXME - Only on startup, remove extension_args accessor
+ $c->log->warn("The configuration key 'extension_args' is deprecated; use 'extensions'");
+ }
+
+ my @extensions = $self->extensions ?
+ @{ $self->extensions } : $self->extension_args ?
+ @{ $self->extension_args } : ();
if ( $claimed_uri )
{
my $identity = $csr->claimed_identity($claimed_uri);
unless ( $identity )
{
- Catalyst::Exception->throw($csr->err);
+ if ( $self->errors_are_fatal )
+ {
+ Catalyst::Exception->throw($csr->err);
+ }
+ else
+ {
+ $c->log->error($csr->err . " -- $claimed_uri");
+ $c->detach();
+ }
}
$identity->set_extension_args(@extensions)
}
else
{
- $c->log->debug("Verified OpenID identity failed to load with find_user; bad user_class? Try 'Null.'") if $c->debug;
+ $c->log->debug("Verified OpenID identity failed to load with find_user; bad user_class? Try 'Null.'") if $self->debug;
return;
}
}
else
{
- Catalyst::Exception->throw("Error validating identity: " .
- $csr->err);
+ $self->errors_are_fatal ?
+ Catalyst::Exception->throw("Error validating identity: " . $csr->err)
+ :
+ $c->log->error( $csr->err);
}
}
return;
=head1 VERSION
-0.14_03
+0.16
-=head1 BACKWARDS COMPATIBILITY CHANGE
+=head1 BACKWARDS COMPATIBILITY CHANGES
-B<NB>: The extenstions were previously configured under the key C<extension_args>. They are now configured under C<extensions>. This prevents the need for double configuration but it breaks extensions in your application if you do not change the name. The old version is supported for now but may be phased out at any time.
+=head2 EXTENSION_ARGS v EXTENSIONS
+
+B<NB>: The extensions were previously configured under the key C<extension_args>. They are now configured under C<extensions>. This prevents the need for double configuration but it breaks extensions in your application if you do not change the name. The old version is supported for now but may be phased out at any time.
As previously noted, L</EXTENSIONS TO OPENID>, I have not tested the extensions. I would be grateful for any feedback or, better, tests.
+=head2 FATALS
+
+The problems encountered by failed OpenID operations have always been fatals in the past. This is unexpected behavior for most users as it differs from other credentials. Authentication errors here are no longer fatal. Debug/error output is improved to offset the loss of information. If for some reason you would prefer the legacy/fatal behavior, set the configuration variable C<errors_are_fatal> to a true value.
+
=head1 SYNOPSIS
In MyApp.pm-
<openid>
<credential>
class OpenID
+ ua_class LWP::UserAgent
</credential>
- ua_class LWP::UserAgent
</openid>
</realms>
</Plugin::Authentication>
openid:
credential:
class: OpenID
- ua_class: LWP::UserAgent
+ ua_class: LWP::UserAgent
In a controller, perhaps C<Root::openid>-
}
},
openid => {
- consumer_secret => "Don't bother setting",
- ua_class => "LWP::UserAgent",
- ua_args => {
- whitelisted_hosts => [qw/ 127.0.0.1 localhost /],
- },
credential => {
class => "OpenID",
store => {
class => "OpenID",
},
- },
- extensions => [
- 'http://openid.net/extensions/sreg/1.1',
- {
- required => 'email',
- optional => 'fullname,nickname,timezone',
+ consumer_secret => "Don't bother setting",
+ ua_class => "LWP::UserAgent",
+ # whitelist is only relevant for LWPx::ParanoidAgent
+ ua_args => {
+ whitelisted_hosts => [qw/ 127.0.0.1 localhost /],
},
- ],
+ extensions => [
+ 'http://openid.net/extensions/sreg/1.1',
+ {
+ required => 'email',
+ optional => 'fullname,nickname,timezone',
+ },
+ ],
+ },
},
},
}
</credential>
</members>
<openid>
- <ua_args>
- whitelisted_hosts 127.0.0.1
- whitelisted_hosts localhost
- </ua_args>
- consumer_secret Don't bother setting
- ua_class LWP::UserAgent
<credential>
<store>
class OpenID
</store>
class OpenID
+ <ua_args>
+ whitelisted_hosts 127.0.0.1
+ whitelisted_hosts localhost
+ </ua_args>
+ consumer_secret Don't bother setting
+ ua_class LWP::UserAgent
+ <extensions>
+ http://openid.net/extensions/sreg/1.1
+ required email
+ optional fullname,nickname,timezone
+ </extensions>
</credential>
- <extensions>
- http://openid.net/extensions/sreg/1.1
- required email
- optional fullname,nickname,timezone
- </extensions>
</openid>
</realms>
</Plugin::Authentication>
class: OpenID
store:
class: OpenID
- consumer_secret: Don't bother setting
- ua_class: LWP::UserAgent
- ua_args:
- whitelisted_hosts:
- - 127.0.0.1
- - localhost
- extensions:
- - http://openid.net/extensions/sreg/1.1
- - required: email
- optional: fullname,nickname,timezone
+ consumer_secret: Don't bother setting
+ ua_class: LWP::UserAgent
+ ua_args:
+ # whitelist is only relevant for LWPx::ParanoidAgent
+ whitelisted_hosts:
+ - 127.0.0.1
+ - localhost
+ extensions:
+ - http://openid.net/extensions/sreg/1.1
+ - required: email
+ optional: fullname,nickname,timezone
B<NB>: There is no OpenID store yet.
=head2 MORE ON CONFIGURATION
-These are set in your realm. See above.
-
=over 4
=item ua_args and ua_class
-L<LWPx::ParanoidAgent> is the default agent E<mdash> C<ua_class>
-E<mdash> if it's available, L<LWP::UserAgent> if not. You don't have
-to set it. I recommend that you do B<not> override it. You can with
-any well behaved L<LWP::UserAgent>. You probably should not.
-L<LWPx::ParanoidAgent> buys you many defenses and extra security
-checks. When you allow your application users freedom to initiate
-external requests, you open an avenue for DoS (denial of service)
-attacks. L<LWPx::ParanoidAgent> defends against this.
-L<LWP::UserAgent> and any regular subclass of it will not.
+L<LWPx::ParanoidAgent> is the default agent E<mdash> C<ua_class> E<mdash> if it's available, L<LWP::UserAgent> if not. You don't have to set
+it. I recommend that you do B<not> override it. You can with any well behaved L<LWP::UserAgent>. You probably should not.
+L<LWPx::ParanoidAgent> buys you many defenses and extra security checks. When you allow your application users freedom to initiate external
+requests, you open an avenue for DoS (denial of service) attacks. L<LWPx::ParanoidAgent> defends against this. L<LWP::UserAgent> and any
+regular subclass of it will not.
=item consumer_secret
-The underlying L<Net::OpenID::Consumer> object is seeded with a
-secret. If it's important to you to set your own, you can. The default
-uses this package name + its version + the sorted configuration keys
-of your Catalyst application (chopped at 255 characters if it's
-longer). This should generally be superior to any fixed string.
+The underlying L<Net::OpenID::Consumer> object is seeded with a secret. If it's important to you to set your own, you can. The default uses
+this package name + its version + the sorted configuration keys of your Catalyst application (chopped at 255 characters if it's longer).
+This should generally be superior to any fixed string.
=back
Support more of the new methods in the L<Net::OpenID> kit.
-There are some interesting implications with this sort of setup. Does
-a user aggregate realms or can a user be signed in under more than one
-realm? The documents could contain a recipe of the self-answering
-OpenID end-point that is in the tests.
+There are some interesting implications with this sort of setup. Does a user aggregate realms or can a user be signed in under more than one
+realm? The documents could contain a recipe of the self-answering OpenID end-point that is in the tests.
-Debug statements need to be both expanded and limited via realm
-configuration.
+Debug statements need to be both expanded and limited via realm configuration.
Better diagnostics in errors. Debug info at all consumer calls.
=head1 DISCLAIMER OF WARRANTY
-Because this software is licensed free of charge, there is no warranty
-for the software, to the extent permitted by applicable law. Except when
-otherwise stated in writing the copyright holders and other parties
-provide the software "as is" without warranty of any kind, either
-expressed or implied, including, but not limited to, the implied
-warranties of merchantability and fitness for a particular purpose. The
-entire risk as to the quality and performance of the software is with
-you. Should the software prove defective, you assume the cost of all
+Because this software is licensed free of charge, there is no warranty for the software, to the extent permitted by applicable law. Except
+when otherwise stated in writing the copyright holders and other parties provide the software "as is" without warranty of any kind, either
+expressed or implied, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose. The
+entire risk as to the quality and performance of the software is with you. Should the software prove defective, you assume the cost of all
necessary servicing, repair, or correction.
-In no event unless required by applicable law or agreed to in writing
-will any copyright holder, or any other party who may modify or
-redistribute the software as permitted by the above license, be
-liable to you for damages, including any general, special, incidental,
-or consequential damages arising out of the use or inability to use
-the software (including but not limited to loss of data or data being
-rendered inaccurate or losses sustained by you or third parties or a
-failure of the software to operate with any other software), even if
-such holder or other party has been advised of the possibility of
-such damages.
+In no event unless required by applicable law or agreed to in writing will any copyright holder, or any other party who may modify or
+redistribute the software as permitted by the above license, be liable to you for damages, including any general, special, incidental, or
+consequential damages arising out of the use or inability to use the software (including but not limited to loss of data or data being
+rendered inaccurate or losses sustained by you or third parties or a failure of the software to operate with any other software), even if
+such holder or other party has been advised of the possibility of such damages.
=head1 SEE ALSO
=item OpenID
-L<Net::OpenID::Server>, L<Net::OpenID::VerifiedIdentity>, L<Net::OpenID::Consumer>, L<http://openid.net/>, L<http://openid.net/developers/specs/>, and L<http://openid.net/extensions/sreg/1.1>.
+L<Net::OpenID::Server>, L<Net::OpenID::VerifiedIdentity>, L<Net::OpenID::Consumer>, L<http://openid.net/>,
+L<http://openid.net/developers/specs/>, and L<http://openid.net/extensions/sreg/1.1>.
=item Catalyst Authentication
-L<Catalyst>, L<Catalyst::Plugin::Authentication>, L<Catalyst::Manual::Tutorial::Authorization>, and L<Catalyst::Manual::Tutorial::Authentication>.
+L<Catalyst>, L<Catalyst::Plugin::Authentication>, L<Catalyst::Manual::Tutorial::Authorization>, and
+L<Catalyst::Manual::Tutorial::Authentication>.
=item Catalyst Configuration