line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Dropbox::Auth; |
2
|
10
|
|
|
10
|
|
74
|
use strict; |
|
10
|
|
|
|
|
21
|
|
|
10
|
|
|
|
|
301
|
|
3
|
10
|
|
|
10
|
|
47
|
use warnings; |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
304
|
|
4
|
10
|
|
|
10
|
|
48
|
use parent qw(Exporter); |
|
10
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
72
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our @EXPORT = do { |
7
|
10
|
|
|
10
|
|
668
|
no strict 'refs'; |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
4443
|
|
8
|
|
|
|
|
|
|
grep { $_ !~ qr{ \A [A-Z]+ \z }xms } keys %{ __PACKAGE__ . '::' }; |
9
|
|
|
|
|
|
|
}; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# https://www.dropbox.com/developers/documentation/http/documentation#oauth2-authorize |
12
|
|
|
|
|
|
|
sub authorize { |
13
|
0
|
|
|
0
|
0
|
|
my ($self, $params) = @_; |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
0
|
|
|
|
$params ||= {}; |
16
|
0
|
|
0
|
|
|
|
$params->{response_type} ||= 'code'; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
my $url = URI->new('https://www.dropbox.com/oauth2/authorize'); |
19
|
0
|
|
|
|
|
|
$url->query_form( |
20
|
|
|
|
|
|
|
client_id => $self->key, |
21
|
|
|
|
|
|
|
%$params, |
22
|
|
|
|
|
|
|
); |
23
|
0
|
|
|
|
|
|
$url->as_string; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# https://www.dropbox.com/developers/documentation/http/documentation#oauth2-token |
27
|
|
|
|
|
|
|
sub token { |
28
|
0
|
|
|
0
|
0
|
|
my ($self, $code, $redirect_uri) = @_; |
29
|
|
|
|
|
|
|
|
30
|
0
|
0
|
|
|
|
|
my $data = $self->api({ |
31
|
|
|
|
|
|
|
url => 'https://api.dropboxapi.com/oauth2/token', |
32
|
|
|
|
|
|
|
params => { |
33
|
|
|
|
|
|
|
client_id => $self->key, |
34
|
|
|
|
|
|
|
client_secret => $self->secret, |
35
|
|
|
|
|
|
|
grant_type => 'authorization_code', |
36
|
|
|
|
|
|
|
code => $code, |
37
|
|
|
|
|
|
|
( $redirect_uri ? ( redirect_uri => $redirect_uri ) : () ), |
38
|
|
|
|
|
|
|
}, |
39
|
|
|
|
|
|
|
}); |
40
|
|
|
|
|
|
|
|
41
|
0
|
0
|
0
|
|
|
|
if ($data && $data->{access_token}) { |
42
|
0
|
|
|
|
|
|
$self->access_token($data->{access_token}); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
$data; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# https://www.dropbox.com/developers/documentation/http/documentation#oauth2-token |
49
|
|
|
|
|
|
|
# This uses the token method with a refresh token to get an updated access token. |
50
|
|
|
|
|
|
|
sub refresh_access_token { |
51
|
0
|
|
|
0
|
0
|
|
my ($self, $refresh_token) = @_; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my $data = $self->api({ |
54
|
|
|
|
|
|
|
url => 'https://api.dropboxapi.com/oauth2/token', |
55
|
|
|
|
|
|
|
params => { |
56
|
|
|
|
|
|
|
client_id => $self->key, |
57
|
|
|
|
|
|
|
client_secret => $self->secret, |
58
|
|
|
|
|
|
|
grant_type => 'refresh_token', |
59
|
|
|
|
|
|
|
refresh_token => $refresh_token, |
60
|
|
|
|
|
|
|
}, |
61
|
|
|
|
|
|
|
}); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# at this point the access token should be in $data |
64
|
|
|
|
|
|
|
# so set it like WebService::Dropbox::Auth::token does |
65
|
0
|
0
|
0
|
|
|
|
if ($data && $data->{access_token}) { |
66
|
0
|
|
|
|
|
|
$self->access_token($data->{access_token}); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$data; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# https://www.dropbox.com/developers/documentation/http/documentation#auth-token-revoke |
73
|
|
|
|
|
|
|
sub revoke { |
74
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my $res = $self->api({ |
77
|
|
|
|
|
|
|
url => 'https://api.dropboxapi.com/2/auth/token/revoke', |
78
|
|
|
|
|
|
|
}); |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
$self->access_token(undef); |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
$res; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |