| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::OpenID::Consumer::Lite; |
|
2
|
1
|
|
|
1
|
|
51448
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
33
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
26
|
|
|
4
|
1
|
|
|
1
|
|
23
|
use 5.00800; |
|
|
1
|
|
|
|
|
7
|
|
|
|
1
|
|
|
|
|
68
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
|
6
|
1
|
|
|
1
|
|
5306
|
use LWP::UserAgent; |
|
|
1
|
|
|
|
|
114372
|
|
|
|
1
|
|
|
|
|
29
|
|
|
7
|
1
|
|
|
1
|
|
9
|
use Carp (); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
101
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $TIMEOUT = 4; |
|
10
|
|
|
|
|
|
|
our $IGNORE_SSL_ERROR = 0; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _ua { |
|
13
|
0
|
|
|
0
|
|
|
my $agent = "Net::OpenID::Consumer::Lite/$Net::OpenID::Consumer::Lite::VERSION"; |
|
14
|
0
|
|
|
|
|
|
LWP::UserAgent->new( |
|
15
|
|
|
|
|
|
|
agent => $agent, |
|
16
|
|
|
|
|
|
|
timeout => $TIMEOUT, |
|
17
|
|
|
|
|
|
|
max_redirect => 0, |
|
18
|
|
|
|
|
|
|
); |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub _get { |
|
22
|
0
|
|
|
0
|
|
|
my $url = shift; |
|
23
|
0
|
|
|
|
|
|
my $ua = _ua(); |
|
24
|
0
|
|
|
|
|
|
my $res = $ua->get($url); |
|
25
|
0
|
0
|
|
|
|
|
unless ($IGNORE_SSL_ERROR) { |
|
26
|
1
|
|
|
1
|
|
2093
|
use Data::Dumper; warn Dumper($res); |
|
|
1
|
|
|
|
|
11168
|
|
|
|
1
|
|
|
|
|
1085
|
|
|
|
0
|
|
|
|
|
|
|
|
27
|
0
|
0
|
|
|
|
|
if ( my $warnings = $res->header('Client-SSL-Warning') ) { |
|
28
|
0
|
|
|
|
|
|
Carp::croak("invalid ssl? ${url}, ${warnings}"); |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
} |
|
31
|
0
|
0
|
|
|
|
|
unless ($res->is_success) { |
|
32
|
0
|
|
|
|
|
|
Carp::croak("cannot get $url : @{[ $res->status_line ]}"); |
|
|
0
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
} |
|
34
|
0
|
|
|
|
|
|
$res; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub check_url { |
|
38
|
0
|
|
|
0
|
0
|
|
my ($class, $server_url, $return_to, $extensions) = (shift, shift, shift, shift); |
|
39
|
0
|
0
|
|
|
|
|
Carp::croak("missing params") unless $return_to; |
|
40
|
0
|
0
|
|
|
|
|
Carp::croak("this module supports only https: $server_url") unless $server_url =~ /^https/; |
|
41
|
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my $url = URI->new($server_url); |
|
43
|
0
|
|
|
|
|
|
my %args = ( |
|
44
|
|
|
|
|
|
|
'openid.mode' => 'checkid_immediate', |
|
45
|
|
|
|
|
|
|
'openid.return_to' => $return_to, |
|
46
|
|
|
|
|
|
|
); |
|
47
|
0
|
0
|
|
|
|
|
if ($extensions) { |
|
48
|
0
|
|
|
|
|
|
my $i = 1; |
|
49
|
0
|
|
|
|
|
|
while (my ($ns, $args) = each %$extensions) { |
|
50
|
0
|
|
|
|
|
|
my $ext_alias = "e$i"; |
|
51
|
0
|
|
|
|
|
|
$args{"openid.ns.$ext_alias"} = $ns; |
|
52
|
0
|
|
|
|
|
|
while (my ($key, $val) = each %$args) { |
|
53
|
0
|
|
|
|
|
|
$args{"openid.${ext_alias}.${key}"} = $val; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
0
|
|
|
|
|
|
$i++; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
} |
|
58
|
0
|
|
|
|
|
|
$url->query_form(%args); |
|
59
|
0
|
|
|
|
|
|
return $url->as_string; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _check_authentication { |
|
63
|
0
|
|
|
0
|
|
|
my ($class, $request) = @_; |
|
64
|
0
|
|
|
|
|
|
my $url = do { |
|
65
|
0
|
|
|
|
|
|
$request->{'openid.mode'} = 'check_authentication'; |
|
66
|
0
|
|
|
|
|
|
my $request_url = URI->new($request->{'openid.op_endpoint'}); |
|
67
|
0
|
|
|
|
|
|
$request_url->query_form(%$request); |
|
68
|
0
|
|
|
|
|
|
$request_url; |
|
69
|
|
|
|
|
|
|
}; |
|
70
|
0
|
|
|
|
|
|
my $res = _get($url); |
|
71
|
0
|
0
|
|
|
|
|
$res->is_success() or die "cannot load $url"; |
|
72
|
0
|
|
|
|
|
|
my $content = $res->content; |
|
73
|
0
|
0
|
|
|
|
|
return _parse_keyvalue($content)->{is_valid} ? 1 : 0; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub handle_server_response { |
|
77
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
|
78
|
0
|
|
|
|
|
|
my $request = shift; |
|
79
|
0
|
|
|
|
|
|
my %callbacks_in = @_; |
|
80
|
0
|
|
|
|
|
|
my %callbacks = (); |
|
81
|
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
for my $cb (qw(not_openid setup_required cancelled verified error)) { |
|
83
|
|
|
|
|
|
|
$callbacks{$cb} = delete( $callbacks_in{$cb} ) |
|
84
|
0
|
|
0
|
0
|
|
|
|| sub { Carp::croak( "No " . $cb . " callback" ) }; |
|
|
0
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
my $mode = $request->{'openid.mode'}; |
|
88
|
0
|
0
|
|
|
|
|
unless ($mode) { |
|
89
|
0
|
|
|
|
|
|
return $callbacks{not_openid}->(); |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
0
|
0
|
|
|
|
|
if ($mode eq 'cancel') { |
|
93
|
0
|
|
|
|
|
|
return $callbacks{cancelled}->(); |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
0
|
0
|
|
|
|
|
if (my $url = $request->{'openid.user_setup_url'}) { |
|
97
|
0
|
|
|
|
|
|
return $callbacks{'setup_required'}->($url); |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
0
|
0
|
|
|
|
|
if ($class->_check_authentication($request)) { |
|
101
|
0
|
|
|
|
|
|
my $vident; |
|
102
|
0
|
|
|
|
|
|
for my $key (split /,/, $request->{'openid.signed'}) { |
|
103
|
0
|
|
|
|
|
|
$vident->{$key} = $request->{"openid.$key"}; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
0
|
|
|
|
|
|
return $callbacks{'verified'}->($vident); |
|
106
|
|
|
|
|
|
|
} else { |
|
107
|
0
|
|
|
|
|
|
return $callbacks{'error'}->(); |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub _parse_keyvalue { |
|
112
|
0
|
|
|
0
|
|
|
my $reply = shift; |
|
113
|
0
|
|
|
|
|
|
my %ret; |
|
114
|
0
|
|
|
|
|
|
$reply =~ s/\r//g; |
|
115
|
0
|
|
|
|
|
|
foreach ( split /\n/, $reply ) { |
|
116
|
0
|
0
|
|
|
|
|
next unless /^(\S+?):(.*)/; |
|
117
|
0
|
|
|
|
|
|
$ret{$1} = $2; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
0
|
|
|
|
|
|
return \%ret; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; |
|
124
|
|
|
|
|
|
|
__END__ |