line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OpenID::Lite::Provider::Response; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
7
|
use Any::Moose; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
4
|
1
|
|
|
1
|
|
805
|
use OpenID::Lite::Constants::ProviderResponseType qw(:all); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
188
|
|
5
|
1
|
|
|
1
|
|
7
|
use OpenID::Lite::Constants::ModeType qw(:all); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
367
|
|
6
|
1
|
|
|
1
|
|
9
|
use OpenID::Lite::Constants::Namespace qw(:all); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
148
|
|
7
|
1
|
|
|
1
|
|
7
|
use OpenID::Lite::Message; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
8
|
1
|
|
|
1
|
|
104
|
use OpenID::Lite::Realm; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use OpenID::Lite::Nonce; |
10
|
|
|
|
|
|
|
use OpenID::Lite::SignatureMethods; |
11
|
|
|
|
|
|
|
use URI; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has 'type' => ( |
14
|
|
|
|
|
|
|
is => 'ro', |
15
|
|
|
|
|
|
|
isa => 'Str', |
16
|
|
|
|
|
|
|
required => 1, |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has 'setup_url' => ( |
20
|
|
|
|
|
|
|
is => 'ro', |
21
|
|
|
|
|
|
|
isa => 'Str', |
22
|
|
|
|
|
|
|
default => '', |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has 'endpoint_url' => ( |
26
|
|
|
|
|
|
|
is => 'ro', |
27
|
|
|
|
|
|
|
isa => 'Str', |
28
|
|
|
|
|
|
|
default => '', |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has 'setup_params' => ( |
32
|
|
|
|
|
|
|
is => 'ro', |
33
|
|
|
|
|
|
|
isa => 'HashRef', |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
has 'assoc_builder' => ( |
37
|
|
|
|
|
|
|
is => 'ro', |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has 'req_params' => ( |
41
|
|
|
|
|
|
|
is => 'ro', |
42
|
|
|
|
|
|
|
isa => 'OpenID::Lite::Message', |
43
|
|
|
|
|
|
|
required => 1, |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
has 'res_params' => ( |
47
|
|
|
|
|
|
|
is => 'ro', |
48
|
|
|
|
|
|
|
isa => 'OpenID::Lite::Message', |
49
|
|
|
|
|
|
|
required => 1, |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
has 'errstr' => ( |
53
|
|
|
|
|
|
|
is => 'ro', |
54
|
|
|
|
|
|
|
isa => 'Str', |
55
|
|
|
|
|
|
|
default => '', |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub is_for_setup { |
59
|
|
|
|
|
|
|
my $self = shift; |
60
|
|
|
|
|
|
|
return $self->type eq SETUP; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub is_for_direct_communication { |
64
|
|
|
|
|
|
|
my $self = shift; |
65
|
|
|
|
|
|
|
return $self->type eq DIRECT; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub is_checkid_error { |
69
|
|
|
|
|
|
|
my $self = shift; |
70
|
|
|
|
|
|
|
return $self->type eq CHECKID_ERROR; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub is_positive_assertion { |
74
|
|
|
|
|
|
|
my $self = shift; |
75
|
|
|
|
|
|
|
return $self->type eq POSITIVE_ASSERTION; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub requires_setup { |
79
|
|
|
|
|
|
|
my $self = shift; |
80
|
|
|
|
|
|
|
return $self->type eq REQUIRES_SETUP; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub add_extension { |
84
|
|
|
|
|
|
|
my ( $self, $extension ) = @_; |
85
|
|
|
|
|
|
|
confess |
86
|
|
|
|
|
|
|
q{add_extension works when is_for_setup or is_positive_assertion returns true} |
87
|
|
|
|
|
|
|
unless $self->is_for_setup || $self->is_positive_assertion; |
88
|
|
|
|
|
|
|
$extension->append_to_params( $self->res_params ); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub make_signed_url { |
92
|
|
|
|
|
|
|
my $self = shift; |
93
|
|
|
|
|
|
|
confess |
94
|
|
|
|
|
|
|
q{make_singed_url works when is_for_setup or is_positive_assertion returns true} |
95
|
|
|
|
|
|
|
unless $self->is_for_setup || $self->is_positive_assertion; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my $identity = $self->res_params->get('identity'); |
98
|
|
|
|
|
|
|
my $claimed_id = $self->res_params->get('claimed_id'); |
99
|
|
|
|
|
|
|
my $return_to = $self->res_params->get('return_to'); |
100
|
|
|
|
|
|
|
my $assoc_handle = $self->res_params->get('assoc_handle'); |
101
|
|
|
|
|
|
|
my $ns = $self->res_params->get('ns'); |
102
|
|
|
|
|
|
|
my $realm = $self->res_params->get('realm') |
103
|
|
|
|
|
|
|
|| $self->res_params->get('trust_root'); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
unless ( OpenID::Lite::Realm->check_url( $realm, $return_to ) ) { |
106
|
|
|
|
|
|
|
$self->errstr(q{Invalid realm}); |
107
|
|
|
|
|
|
|
return; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# check association |
111
|
|
|
|
|
|
|
my $assoc; |
112
|
|
|
|
|
|
|
my $invalidate_handle; |
113
|
|
|
|
|
|
|
if ($assoc_handle) { |
114
|
|
|
|
|
|
|
my $found = $self->assoc_builder->build_from_handle( |
115
|
|
|
|
|
|
|
$assoc_handle => { dumb => 0, } ); |
116
|
|
|
|
|
|
|
if ( $found && !$found->is_expired ) { |
117
|
|
|
|
|
|
|
$assoc = $found; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
else { |
120
|
|
|
|
|
|
|
$invalidate_handle = $assoc_handle; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
unless ($assoc) { |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
$assoc = $self->assoc_builder->build_association( |
127
|
|
|
|
|
|
|
type => q{HMAC-SHA1}, |
128
|
|
|
|
|
|
|
dumb => 1, |
129
|
|
|
|
|
|
|
); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
$claimed_id ||= $identity; |
133
|
|
|
|
|
|
|
$claimed_id = $identity if $claimed_id eq IDENTIFIER_SELECT; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
#my $res_params = OpenID::Lite::Message->new; |
136
|
|
|
|
|
|
|
my $res_params = $self->res_params->copy(); |
137
|
|
|
|
|
|
|
$res_params->set( ns => $ns ) if $ns; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
$res_params->set( mode => ID_RES ); |
140
|
|
|
|
|
|
|
$res_params->set( identity => $identity ); |
141
|
|
|
|
|
|
|
$res_params->set( return_to => $return_to ); |
142
|
|
|
|
|
|
|
$res_params->set( assoc_handle => $assoc->handle ); |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
$res_params->set( invalidate_handle => $invalidate_handle ) |
145
|
|
|
|
|
|
|
if $invalidate_handle; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
if ( $res_params->is_openid2 ) { |
148
|
|
|
|
|
|
|
$res_params->set( claimed_id => $claimed_id ); |
149
|
|
|
|
|
|
|
$res_params->set( response_nonce => OpenID::Lite::Nonce->gen_nonce ); |
150
|
|
|
|
|
|
|
$res_params->set( op_endpoint => $self->endpoint_url ); |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
$res_params->set_signed(); |
154
|
|
|
|
|
|
|
my $signature_method |
155
|
|
|
|
|
|
|
= OpenID::Lite::SignatureMethods->select_method( $assoc->type ); |
156
|
|
|
|
|
|
|
my $signature = $signature_method->sign( $assoc->secret, $res_params ); |
157
|
|
|
|
|
|
|
$res_params->set( sig => $signature ); |
158
|
|
|
|
|
|
|
return $res_params->to_url($return_to); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub make_cancel_url { |
162
|
|
|
|
|
|
|
my $self = shift; |
163
|
|
|
|
|
|
|
my $params = OpenID::Lite::Message->new; |
164
|
|
|
|
|
|
|
$params->set( ns => $self->req_params->get('ns') ) |
165
|
|
|
|
|
|
|
if $self->req_params->get('ns'); |
166
|
|
|
|
|
|
|
$params->set( mode => CANCEL ); |
167
|
|
|
|
|
|
|
return $params->to_url( $self->req_params->get('return_to') ); |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub make_setup_url { |
171
|
|
|
|
|
|
|
my $self = shift; |
172
|
|
|
|
|
|
|
confess q{no setup_url found.} unless $self->setup_url; |
173
|
|
|
|
|
|
|
confess |
174
|
|
|
|
|
|
|
q{make_setup_url works when requires_setup or is_for_setup returns true.} |
175
|
|
|
|
|
|
|
unless $self->requires_setup || $self->is_for_setup; |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
my $params = OpenID::Lite::Message->new; |
178
|
|
|
|
|
|
|
my $surl = URI->new( $self->setup_url ); |
179
|
|
|
|
|
|
|
$surl->query_form( %{ $self->setup_params } ) |
180
|
|
|
|
|
|
|
if $self->setup_params; |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
my $mode = $self->req_params->get('mode'); |
183
|
|
|
|
|
|
|
if ( $mode eq CHECKID_IMMEDIATE ) { |
184
|
|
|
|
|
|
|
if ( $self->req_params->is_openid2 ) { |
185
|
|
|
|
|
|
|
$params->set( ns => $self->req_params->get('ns') ); |
186
|
|
|
|
|
|
|
$params->set( mode => SETUP_NEEDED ); |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
else { |
189
|
|
|
|
|
|
|
$params->set( mode => ID_RES ); |
190
|
|
|
|
|
|
|
$params->set( user_setup_url => $surl->as_string ); |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
return $params->to_url( $self->req_params->get('return_to') ); |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
sub make_error_url { |
197
|
|
|
|
|
|
|
my $self = shift; |
198
|
|
|
|
|
|
|
unless ( $self->is_checkid_error ) { |
199
|
|
|
|
|
|
|
confess 'make_error_url can be called only when the response-type is checkid error.'; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
$self->res_params->to_url( $self->req_params->get('return_to') ); |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
sub content { |
205
|
|
|
|
|
|
|
my $self = shift; |
206
|
|
|
|
|
|
|
if ( $self->is_for_direct_communication ) { |
207
|
|
|
|
|
|
|
return $self->res_params->to_key_value; |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
else { |
210
|
|
|
|
|
|
|
confess |
211
|
|
|
|
|
|
|
q{content shouldn't be called when the response is for redirect or setup}; |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
sub get_realm { |
216
|
|
|
|
|
|
|
my $self = shift; |
217
|
|
|
|
|
|
|
confess |
218
|
|
|
|
|
|
|
q{get_realm works when is_for_setup or is_positive_assertion returns true} |
219
|
|
|
|
|
|
|
unless $self->is_for_setup || $self->is_positive_assertion; |
220
|
|
|
|
|
|
|
return $self->res_params->get('realm') || $self->res_params->get('trust_root'); |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
sub get_identity { |
224
|
|
|
|
|
|
|
my $self = shift; |
225
|
|
|
|
|
|
|
confess |
226
|
|
|
|
|
|
|
q{get_identity works when is_for_setup or is_positive_assertion returns true} |
227
|
|
|
|
|
|
|
unless $self->is_for_setup || $self->is_positive_assertion; |
228
|
|
|
|
|
|
|
return $self->res_params->get('identity'); |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
sub set_identity { |
232
|
|
|
|
|
|
|
my $self = shift; |
233
|
|
|
|
|
|
|
my $identity = shift; |
234
|
|
|
|
|
|
|
confess |
235
|
|
|
|
|
|
|
q{get_identity works when is_for_setup or is_positive_assertion returns true} |
236
|
|
|
|
|
|
|
unless $self->is_for_setup || $self->is_positive_assertion; |
237
|
|
|
|
|
|
|
return $self->res_params->set('identity' => $identity); |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
sub get_claimed_id { |
241
|
|
|
|
|
|
|
my $self = shift; |
242
|
|
|
|
|
|
|
confess |
243
|
|
|
|
|
|
|
q{get_claimed_id works when is_for_setup or is_positive_assertion returns true} |
244
|
|
|
|
|
|
|
unless $self->is_for_setup || $self->is_positive_assertion; |
245
|
|
|
|
|
|
|
return $self->res_params->get('claimed_id'); |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
no Any::Moose; |
249
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
250
|
|
|
|
|
|
|
1; |