line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Plugin::Authentication::Credential::AOL; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
56
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
412
|
use UNIVERSAL::require; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use JSON::Any; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub setup { |
10
|
|
|
|
|
|
|
my $c = shift; |
11
|
|
|
|
|
|
|
my $config = $c->config->{authentication}->{aol} ||= {}; |
12
|
|
|
|
|
|
|
( $config->{user_class} |
13
|
|
|
|
|
|
|
||= "Catalyst::Plugin::Authentication::User::Hash" )->require; |
14
|
|
|
|
|
|
|
$c->NEXT::setup(@_); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub authenticate_aol { |
18
|
|
|
|
|
|
|
my $c = shift; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $config = $c->config->{authentication}->{aol}; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $current = $c->req->uri; |
23
|
|
|
|
|
|
|
$current->query(undef); # no query |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
if ($c->req->params->{token_a}) { |
26
|
|
|
|
|
|
|
my $uri = URI->new("http://api.screenname.aol.com/auth/getInfo"); |
27
|
|
|
|
|
|
|
$uri->query_form( |
28
|
|
|
|
|
|
|
devId => $config->{devId}, |
29
|
|
|
|
|
|
|
f => 'json', |
30
|
|
|
|
|
|
|
# referer needs to be an actual Referer: header, but since |
31
|
|
|
|
|
|
|
# we do redirection, it doesn't match with succUrl :/ |
32
|
|
|
|
|
|
|
referer => $current->as_string, |
33
|
|
|
|
|
|
|
a => $c->req->params->{token_a}, |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(agent => "Catalyst::Plugin::Authentication::Credential::AOL/$VERSION"); |
37
|
|
|
|
|
|
|
my $res = $ua->get($uri); |
38
|
|
|
|
|
|
|
unless ($res->is_success) { |
39
|
|
|
|
|
|
|
$c->log->info("Authentication failure: HTTP error " . $res->status_line); |
40
|
|
|
|
|
|
|
return; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $data = JSON::Any->jsonToObj($res->content); |
44
|
|
|
|
|
|
|
unless (($data->{response}->{statusCode} || '') eq '200') { |
45
|
|
|
|
|
|
|
$c->log->info("Authentication failure: " . $data->{response}->{statusCode}); |
46
|
|
|
|
|
|
|
return; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $user = $data->{response}->{data}->{userData}; |
50
|
|
|
|
|
|
|
$c->log->debug("Successfully authenticated user '$user->{loginId}'.") |
51
|
|
|
|
|
|
|
if $c->debug; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my $store = $config->{store} || $c->default_auth_store; |
54
|
|
|
|
|
|
|
if ( $store |
55
|
|
|
|
|
|
|
and my $store_user |
56
|
|
|
|
|
|
|
= $store->get_user( $user->{loginId}, $user ) ) { |
57
|
|
|
|
|
|
|
$c->set_authenticated($store_user); |
58
|
|
|
|
|
|
|
} else { |
59
|
|
|
|
|
|
|
$user = $config->{user_class}->new($user); |
60
|
|
|
|
|
|
|
$c->set_authenticated($user); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
return 1; |
64
|
|
|
|
|
|
|
} else { |
65
|
|
|
|
|
|
|
my $uri = URI->new("http://api.screenname.aol.com/auth/login"); |
66
|
|
|
|
|
|
|
$uri->query_form( |
67
|
|
|
|
|
|
|
devId => $config->{devId}, |
68
|
|
|
|
|
|
|
succUrl => $current, |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
$c->res->redirect($uri); |
72
|
|
|
|
|
|
|
return; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
__END__ |