line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Amon2::Auth::Site::Instagram; |
2
|
1
|
|
|
1
|
|
1708
|
use Mouse; |
|
1
|
|
|
|
|
33382
|
|
|
1
|
|
|
|
|
5
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
299
|
use JSON; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
5
|
1
|
|
|
1
|
|
1470
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
52528
|
|
|
1
|
|
|
|
|
27
|
|
6
|
1
|
|
|
1
|
|
10
|
use URI; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
182
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has client_id => ( |
11
|
|
|
|
|
|
|
is => 'ro', |
12
|
|
|
|
|
|
|
isa => 'Str', |
13
|
|
|
|
|
|
|
required => 1, |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has client_secret => ( |
17
|
|
|
|
|
|
|
is => 'ro', |
18
|
|
|
|
|
|
|
isa => 'Str', |
19
|
|
|
|
|
|
|
required => 1, |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has redirect_url => ( |
23
|
|
|
|
|
|
|
is => 'ro', |
24
|
|
|
|
|
|
|
isa => 'Str', |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has scope => ( |
28
|
|
|
|
|
|
|
is => 'ro', |
29
|
|
|
|
|
|
|
isa => 'Str', |
30
|
|
|
|
|
|
|
default => sub { 'basic' }, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has user_info => ( |
34
|
|
|
|
|
|
|
is => 'rw', |
35
|
|
|
|
|
|
|
isa => 'Bool', |
36
|
|
|
|
|
|
|
default => 1, |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
has authorize_url => ( |
40
|
|
|
|
|
|
|
is => 'ro', |
41
|
|
|
|
|
|
|
isa => 'Str', |
42
|
|
|
|
|
|
|
default => 'https://api.instagram.com/oauth/authorize', |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
has access_token_url => ( |
46
|
|
|
|
|
|
|
is => 'ro', |
47
|
|
|
|
|
|
|
isa => 'Str', |
48
|
|
|
|
|
|
|
default => 'https://api.instagram.com/oauth/access_token', |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
has ua => ( |
53
|
|
|
|
|
|
|
is => 'ro', |
54
|
|
|
|
|
|
|
isa => 'LWP::UserAgent', |
55
|
|
|
|
|
|
|
lazy => 1, |
56
|
|
|
|
|
|
|
default => sub { |
57
|
|
|
|
|
|
|
LWP::UserAgent->new(agent => "Amon2::Auth::Site::Instagram/$VERSION"); |
58
|
|
|
|
|
|
|
}, |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
1
|
|
|
1
|
|
6
|
no Mouse; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
10
|
|
62
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
0
|
0
|
|
sub moniker { 'instagram' } |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub auth_uri { |
67
|
0
|
|
|
0
|
0
|
|
my ($self, $c, $callback_url) = @_; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my $uri = URI->new($self->authorize_url); |
70
|
0
|
|
|
|
|
|
$uri->query_form( |
71
|
|
|
|
|
|
|
client_id => $self->client_id, |
72
|
|
|
|
|
|
|
redirect_uri => $self->redirect_url, |
73
|
|
|
|
|
|
|
response_type => 'code', |
74
|
|
|
|
|
|
|
scope => $self->scope, |
75
|
|
|
|
|
|
|
); |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
return $uri->as_string; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub callback { |
81
|
0
|
|
|
0
|
1
|
|
my ($self, $c, $callback) = @_; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my $res = $self->ua->post($self->access_token_url, +{ |
84
|
|
|
|
|
|
|
client_id => $self->client_id, |
85
|
|
|
|
|
|
|
client_secret => $self->client_secret, |
86
|
|
|
|
|
|
|
grant_type => 'authorization_code', |
87
|
|
|
|
|
|
|
redirect_uri => $self->redirect_url, |
88
|
|
|
|
|
|
|
code => $c->req->param('code'), |
89
|
|
|
|
|
|
|
}); |
90
|
0
|
0
|
|
|
|
|
$res->is_success or do { |
91
|
0
|
|
|
|
|
|
warn $res->decoded_content; |
92
|
0
|
|
|
|
|
|
return $callback->{on_error}->($res->decoded_content); |
93
|
|
|
|
|
|
|
}; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
$res = decode_json $res->content; |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
my @args = ($res->{access_token}); |
98
|
0
|
0
|
|
|
|
|
push @args, $res->{user} if $self->user_info; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
$callback->{on_finished}->(@args); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |
106
|
|
|
|
|
|
|
__END__ |