Net-OpenID-Consumer
view release on metacpan or search on metacpan
lib/Net/OpenID/Consumer.pm view on Meta::CPAN
unless ($claimed_identity) {
die "not actually an openid? " . $csr->err;
}
# We can then launch the actual authentication of this identity.
# The first step is to redirect the user to the appropriate URL at
# the identity provider. This URL is constructed as follows:
#
my $check_url = $claimed_identity->check_url(
return_to => "http://example.com/openid-check.app?yourarg=val",
trust_root => "http://example.com/",
# to do a "checkid_setup mode" request, in which the user can
# interact with the provider, e.g., so that the user can sign in
# there if s/he has not done so already, you will need this,
delayed_return => 1
# otherwise, this will be a "check_immediate mode" request, the
# provider will have to immediately return some kind of answer
# without interaction
);
# Once you redirect the user to $check_url, the provider should
# eventually redirect back, at which point you need some kind of
# handler at openid-check.app to deal with that response.
# You can either use the callback-based API (recommended)...
#
$csr->handle_server_response(
not_openid => sub {
die "Not an OpenID message";
},
setup_needed => sub {
if ($csr->message->protocol_version >= 2) {
# (OpenID 2) retry request in checkid_setup mode (above)
}
else {
# (OpenID 1) redirect user to $csr->user_setup_url
}
},
cancelled => sub {
# User hit cancel; restore application state prior to check_url
},
verified => sub {
my ($vident) = @_;
my $verified_url = $vident->url;
print "You are $verified_url !";
},
error => sub {
my ($errcode,$errtext) = @_;
die("Error validating identity: $errcode: $errcode");
},
);
# ... or handle the various cases yourself
#
unless ($csr->is_server_response) {
die "Not an OpenID message";
} elsif ($csr->setup_needed) {
# (OpenID 2) retry request in checkid_setup mode
# (OpenID 1) redirect/link/popup user to $csr->user_setup_url
} elsif ($csr->user_cancel) {
# User hit cancel; restore application state prior to check_url
} elsif (my $vident = $csr->verified_identity) {
my $verified_url = $vident->url;
print "You are $verified_url !";
} else {
die "Error validating identity: " . $csr->err;
}
=head1 DESCRIPTION
This is the Perl API for (the consumer half of) OpenID, a distributed
identity system based on proving you own a URL, which is then your
identity. More information is available at:
http://openid.net/
=head1 CONSTRUCTOR
=over 4
=item B<new>
my $csr = Net::OpenID::Consumer->new( %options );
The following option names are recognized:
C<ua>,
C<cache>,
C<args>,
C<consumer_secret>,
C<minimum_version>,
C<required_root>,
C<assoc_options>, and
C<nonce_options>
in the constructor.
In each case the option value is treated exactly as the argument
to the corresponding method described below under L<Configuration|/Configuration>.
=back
=head1 METHODS
=head2 State
=over 4
=item $csr->B<message>($key)
Returns the value for the given key/field from the OpenID protocol
message contained in the request URL parameters (i.e., the value for
the URL parameter C<openid.$key>).
This can only be used to obtain core OpenID fields not extension fields.
Calling this method without a C<$key> argument returns a
L<Net::OpenID::IndirectMessage|Net::OpenID::IndirectMessage>
object representing the protocol message, at which point the
various object methods are available, including
$csr->message->protocol_version
( run in 1.648 second using v1.01-cache-2.11-cpan-364913b4093 )