line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Web::Auth::OAuth; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1178
|
use Mojo::Base 'Mojolicious::Plugin::Web::Auth::Base'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
4
|
1
|
|
|
1
|
|
736
|
use Net::OAuth::Client; |
|
1
|
|
|
|
|
54932
|
|
|
1
|
|
|
|
|
9
|
|
5
|
1
|
|
|
1
|
|
45
|
use Mojo::JSON; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
626
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has 'request_token_url'; |
8
|
|
|
|
|
|
|
has is_v1a => 0; |
9
|
|
|
|
|
|
|
has token_key => 'token'; |
10
|
|
|
|
|
|
|
has token_secret_key => 'token_secret'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub auth_uri { |
13
|
0
|
|
|
0
|
0
|
|
my ( $self, $c, $callback_uri ) = @_; |
14
|
|
|
|
|
|
|
|
15
|
0
|
0
|
|
|
|
|
$callback_uri or die "Missing mandatory parameter: callback_uri"; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
return $self->_client( $c, $callback_uri )->authorize_url; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub callback { |
21
|
0
|
|
|
0
|
0
|
|
my ( $self, $c, $callback ) = @_; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $request_token = $c->req->param('oauth_token') |
24
|
0
|
0
|
|
|
|
|
or return $callback->{on_error}->("Session error"); |
25
|
0
|
|
|
|
|
|
my $request_verifier = $c->req->param('oauth_verifier'); |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
my $client = $self->_client($c); |
28
|
0
|
0
|
|
|
|
|
$client->is_v1a(1) if $self->is_v1a;; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my $access_token = $client->get_access_token($request_token, $request_verifier); |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my $token = $access_token->token; |
33
|
0
|
|
|
|
|
|
my $secret = $access_token->token_secret; |
34
|
0
|
|
|
|
|
|
my @args = ( $token, $secret ); |
35
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
|
if ( $self->user_info ) { |
37
|
0
|
|
|
|
|
|
my $res = $access_token->get( $self->user_info_url ); |
38
|
0
|
0
|
|
|
|
|
return $callback->{on_error}->( $res->decoded_content ) |
39
|
|
|
|
|
|
|
unless ( $res->is_success ); |
40
|
0
|
|
|
|
|
|
push @args, Mojo::JSON::j( $res->decoded_content ); |
41
|
|
|
|
|
|
|
} else { |
42
|
0
|
|
|
|
|
|
push @args, undef; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
return $callback->{on_finished}->(@args); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _client { |
49
|
0
|
|
|
0
|
|
|
my ( $self, $c, $callback_uri ) = @_; |
50
|
|
|
|
|
|
|
return Net::OAuth::Client->new( |
51
|
|
|
|
|
|
|
$self->key, |
52
|
|
|
|
|
|
|
$self->secret, |
53
|
|
|
|
|
|
|
request_token_path => $self->request_token_url, |
54
|
|
|
|
|
|
|
authorize_path => $self->authorize_url, |
55
|
|
|
|
|
|
|
access_token_path => $self->access_token_url, |
56
|
|
|
|
|
|
|
access_token_method => 'POST', |
57
|
|
|
|
|
|
|
callback => $callback_uri, |
58
|
|
|
|
|
|
|
session => sub { |
59
|
0
|
0
|
|
0
|
|
|
if ( @_ > 1 ) { |
|
|
0
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my ($token, $token_secret) = @_; |
61
|
0
|
|
|
|
|
|
$c->session($self->token_key => $token); |
62
|
0
|
|
|
|
|
|
$c->session($self->token_secret_key => $token_secret); |
63
|
0
|
|
|
|
|
|
return; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
elsif ( @_ == 1 ) { |
66
|
0
|
|
|
|
|
|
my $token = $_[0]; |
67
|
0
|
0
|
|
|
|
|
return $c->session($self->token_secret_key) |
68
|
|
|
|
|
|
|
if $token eq $c->session($self->token_key); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
}, |
71
|
0
|
|
|
|
|
|
); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |