Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added more states

  • Loading branch information...
commit 86d46f84a8f99a63e7549a3ee05249459c63e010 1 parent f70d25c
@vti authored
View
12 lib/Protocol/OpenID/Discoverer.pm
@@ -13,20 +13,27 @@ sub discover {
my ($http_req_cb, $tx, $cb) = @_;
if (HAVE_YADIS) {
+ $tx->state('discovery_yadis_start');
Protocol::OpenID::Discoverer::Yadis->discover(
$http_req_cb,
$tx => sub {
my $tx = shift;
- return $cb->($tx) unless $tx->error;
+ unless ($tx->error) {
+ $tx->state('discovery_yadis_done');
+ return $cb->($tx);
+ }
$tx->error(undef);
+ $tx->state('discovery_html_start');
Protocol::OpenID::Discoverer::HTML->discover(
$http_req_cb,
$tx => sub {
my $tx = shift;
+ $tx->state('discovery_html_done') unless $tx->error;
+
return $cb->($tx);
}
);
@@ -34,11 +41,14 @@ sub discover {
);
}
else {
+ $tx->state('discovery_html_start');
Protocol::OpenID::Discoverer::HTML->discover(
$http_req_cb,
$tx => sub {
my $tx = shift;
+ $tx->state('discovery_html_done') unless $tx->error;
+
return $cb->($tx);
}
);
View
23 lib/Protocol/OpenID/RP.pm
@@ -197,7 +197,6 @@ sub authenticate {
}
$tx->identifier($identifier->to_string);
-
$tx->state('identifier');
# 7.3. Discovery
@@ -267,17 +266,18 @@ sub authenticate {
warn 'Save association to the OpenID transaction' if DEBUG;
$tx->response($response);
+ $tx->state('authentication_start');
# Special case, error mode
if ($response->mode eq 'error') {
- warn 'Association has an error' if DEBUG;
+ warn 'Authentication has an error' if DEBUG;
$tx->error($response->param('error'));
return $cb->($self, $tx) if $cb;
return $self->error_cb->($tx);
}
unless ($response->mode eq 'id_res') {
- warn 'Association response is not successful' if DEBUG;
+ warn 'Authentication response is not successful' if DEBUG;
$tx->state($response->mode);
return $cb->($self, $tx) if $cb;
@@ -302,6 +302,8 @@ sub authenticate {
warn 'Verifying assertion' if DEBUG;
+ $tx->state('verification_start');
+
# 11. Verifying Assertions
# The value of "openid.return_to" matches the URL of the current request
@@ -352,7 +354,7 @@ sub _discover {
my $self = shift;
my ($tx, $cb) = @_;
- $tx->state('discovery');
+ $tx->state('discovery_start');
my $identifier = $tx->identifier;
@@ -364,6 +366,8 @@ sub _discover {
warn 'Discovery cache hit' if DEBUG;
$tx->from_hash($cache);
+ $tx->state('discovery_done');
+
return $cb->($self, $tx);
}
@@ -378,6 +382,8 @@ sub _discover {
$tx->to_hash => sub {
warn 'Cached discovery' if DEBUG;
+ $tx->state('discovery_done');
+
return $cb->($self, $tx);
}
);
@@ -402,7 +408,7 @@ sub _associate {
warn 'Performing association' if DEBUG;
- $tx->state('association');
+ $tx->state('association_start');
my $request = Protocol::OpenID::Message::AssociationRequest->new($assoc);
@@ -444,6 +450,7 @@ sub _associate {
# Save association to the transaction
$tx->association($assoc);
+ $tx->state('association_done');
$self->store_cb->($assoc->assoc_handle => $assoc->to_hash =>
sub { return $cb->($self, $tx); });
@@ -455,6 +462,7 @@ sub _associate {
sub _verify_signature {
my ($self, $tx, $cb) = @_;
+ $tx->state('verification_signature_start');
return $self->_verify_signature_directly($tx, $cb) unless $self->find_cb;
warn 'Try to find associaction in cache' if DEBUG;
@@ -479,6 +487,7 @@ sub _verify_signature {
);
}
else {
+ $tx->state('verification_locally_done');
$cb->($self, $tx);
}
}
@@ -494,6 +503,8 @@ sub _verify_signature_directly {
warn 'Verifying signature directly' if DEBUG;
+ $tx->state('verification_directly_start');
+
my $direct_request =
Protocol::OpenID::Message::VerificationRequest->new($tx->response);
@@ -551,6 +562,8 @@ sub _verify_signature_directly_req {
$tx->error('Signature not verified')
if $direct_response->is_valid eq 'false';
+ $tx->start('verification_directly_done');
+
$cb->($self, $tx);
}
);
View
4 lib/Protocol/OpenID/Transaction.pm
@@ -115,6 +115,10 @@ sub to_hash {
$hash->{state} = $self->state;
+ if ($self->association) {
+ $hash->{association} = $self->association->to_hash;
+ }
+
return $hash;
}
View
6 t/transaction.t
@@ -3,10 +3,11 @@
use strict;
use warnings;
-use Test::More tests => 6;
+use Test::More tests => 7;
use Protocol::OpenID;
use Protocol::OpenID::Transaction;
+use Protocol::OpenID::Association;
my $tx = Protocol::OpenID::Transaction->new;
$tx->ns(OPENID_VERSION_2_0);
@@ -43,3 +44,6 @@ is($tx->state, 'init');
$tx->state_cb(sub { ok(1) });
$tx->state('foo');
is($tx->state, 'foo');
+
+$tx->association(Protocol::OpenID::Association->new);
+ok($tx->to_hash->{association}->{secret});
Please sign in to comment.
Something went wrong with that request. Please try again.