line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::DoormanOpenID; |
2
|
1
|
|
|
1
|
|
588
|
use 5.010; |
|
1
|
|
|
|
|
3
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
47
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = "0.06"; |
6
|
|
|
|
|
|
|
our $AUTHORITY = "http://gugod.org"; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use feature qw(switch); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
94
|
|
9
|
1
|
|
|
1
|
|
685
|
use parent 'Doorman::PlackMiddleware'; |
|
1
|
|
|
|
|
263
|
|
|
1
|
|
|
|
|
6
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
901
|
use Plack::Request; |
|
1
|
|
|
|
|
60474
|
|
|
1
|
|
|
|
|
99
|
|
12
|
1
|
|
|
1
|
|
8
|
use Plack::Util::Accessor qw(secret ua); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
848709
|
use Net::OpenID::Consumer; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use LWP::UserAgent; |
16
|
|
|
|
|
|
|
use URI; |
17
|
|
|
|
|
|
|
use Scalar::Util qw(weaken); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub prepare_app { |
20
|
|
|
|
|
|
|
my $self = shift; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$self->SUPER::prepare_app(@_); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
$self->secret( |
25
|
|
|
|
|
|
|
'This is the default consumer_secret value for Net::OpenID::Consumer |
26
|
|
|
|
|
|
|
that you should provide for your own app. ' . $VERSION |
27
|
|
|
|
|
|
|
) unless $self->secret; |
28
|
|
|
|
|
|
|
$self->ua('LWP::UserAgent') unless $self->ua; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub openid_verified_url { |
32
|
|
|
|
|
|
|
$_[0]->scope_url . "/openid_verified"; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub openid_verified_path { |
36
|
|
|
|
|
|
|
URI->new($_[0]->openid_verified_url)->path; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub verified_identity_url { |
40
|
|
|
|
|
|
|
$_[0]->session_get("verified_identity_url"); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub is_sign_in { |
44
|
|
|
|
|
|
|
defined $_[0]->verified_identity_url; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub csr { |
48
|
|
|
|
|
|
|
my ($self, $request) = @_; |
49
|
|
|
|
|
|
|
return Net::OpenID::Consumer->new( |
50
|
|
|
|
|
|
|
ua => ref($self->ua) ? $self->ua : $self->ua->new, |
51
|
|
|
|
|
|
|
args => sub { $request->param($_[0]) }, |
52
|
|
|
|
|
|
|
consumer_secret => $self->secret, |
53
|
|
|
|
|
|
|
required_root => $self->root_url |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub call { |
58
|
|
|
|
|
|
|
my ($self, $env) = @_; |
59
|
|
|
|
|
|
|
$self->prepare_call($env); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
$env->{"doorman.@{[ $self->scope ]}.openid"} = $self; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $request = Plack::Request->new($env); |
64
|
|
|
|
|
|
|
given([$request->method, $request->path]) { |
65
|
|
|
|
|
|
|
when(['POST', $self->sign_in_path]) { |
66
|
|
|
|
|
|
|
my $csr = $self->csr($request); |
67
|
|
|
|
|
|
|
if ($request->param("openid")) { |
68
|
|
|
|
|
|
|
if (my $claimed_identity = $csr->claimed_identity( $request->param("openid") )) { |
69
|
|
|
|
|
|
|
my $check_url = $claimed_identity->check_url( |
70
|
|
|
|
|
|
|
delayed_return => 1, |
71
|
|
|
|
|
|
|
return_to => $self->openid_verified_url, |
72
|
|
|
|
|
|
|
trust_root => $self->root_url |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
return [302, ["Location" => $check_url], [""]]; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
else { |
78
|
|
|
|
|
|
|
$env->{'doorman.'. $self->scope .'.openid.status'} = 'error'; |
79
|
|
|
|
|
|
|
$env->{'doorman.'. $self->scope .'.openid.error'} = $csr->errcode; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
when(['GET', $self->openid_verified_path]) { |
85
|
|
|
|
|
|
|
my $csr = $self->csr($request); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
$csr->handle_server_response( |
88
|
|
|
|
|
|
|
verified => sub { |
89
|
|
|
|
|
|
|
my $id = shift; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$env->{'doorman.'. $self->scope .'.openid.verified_identity'} = $id; |
92
|
|
|
|
|
|
|
$env->{'doorman.'. $self->scope .'.openid.status'} = 'verified'; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
$self->session_set("verified_identity_url", $id->url); |
95
|
|
|
|
|
|
|
}, |
96
|
|
|
|
|
|
|
setup_required => sub { |
97
|
|
|
|
|
|
|
$self->env_set("status", "setup_required"); |
98
|
|
|
|
|
|
|
}, |
99
|
|
|
|
|
|
|
cancelled => sub { |
100
|
|
|
|
|
|
|
$self->env_set("status", "cancelled"); |
101
|
|
|
|
|
|
|
}, |
102
|
|
|
|
|
|
|
not_openid => sub { |
103
|
|
|
|
|
|
|
$self->env_set("status", "not_openid"); |
104
|
|
|
|
|
|
|
}, |
105
|
|
|
|
|
|
|
error => sub { |
106
|
|
|
|
|
|
|
my $err = shift; |
107
|
|
|
|
|
|
|
$self->env_set("status", "error"); |
108
|
|
|
|
|
|
|
$self->env_set("error", $err); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
when(['GET', $self->sign_out_path]) { |
114
|
|
|
|
|
|
|
$self->session_remove("verified_identity_url"); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
return $self->app->($env); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
__END__ |