line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
1810602
|
use strictures; |
|
3
|
|
|
|
|
4931
|
|
|
3
|
|
|
|
|
18
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package WebService::GoogleAPI::Client::AuthStorage::GapiJSON; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.26'; # VERSION |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: Auth Storage Backend based on gapi.json |
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
1818
|
use Moo; |
|
3
|
|
|
|
|
22572
|
|
|
3
|
|
|
|
|
20
|
|
10
|
3
|
|
|
3
|
|
4882
|
use Config::JSON; |
|
3
|
|
|
|
|
93478
|
|
|
3
|
|
|
|
|
97
|
|
11
|
3
|
|
|
3
|
|
26
|
use Carp; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
1853
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
with 'WebService::GoogleAPI::Client::AuthStorage'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has 'path' => (is => 'rw', default => './gapi.json'); # default is gapi.json |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has 'tokensfile' => (is => 'rw'); # Config::JSON object pointer |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# NOTE- this type of class has getters and setters b/c the implementation of |
22
|
|
|
|
|
|
|
# getting and setting depends on what's storing |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub BUILD { |
25
|
3
|
|
|
3
|
0
|
4589
|
my ($self) = @_; |
26
|
3
|
|
|
|
|
41
|
$self->tokensfile(Config::JSON->new($self->path)); |
27
|
3
|
|
|
|
|
5795
|
my $missing = grep !$_, map $self->get_from_storage($_), |
28
|
|
|
|
|
|
|
qw/client_id client_secret/; |
29
|
3
|
50
|
|
|
|
93
|
croak <
|
30
|
|
|
|
|
|
|
Malformed gapi.json detected. We need the client_id and client_secret in order |
31
|
|
|
|
|
|
|
to refresh expired tokens |
32
|
|
|
|
|
|
|
NOCLIENT |
33
|
|
|
|
|
|
|
|
34
|
3
|
|
|
|
|
16
|
return $self; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub get_access_token { |
39
|
|
|
|
|
|
|
my ($self) = @_; |
40
|
|
|
|
|
|
|
my $value = $self->get_from_storage('access_token'); |
41
|
|
|
|
|
|
|
return $value; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub refresh_access_token { |
46
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
47
|
0
|
|
|
|
|
0
|
my %p = map { ($_ => $self->get_from_storage($_)) } |
|
0
|
|
|
|
|
0
|
|
48
|
|
|
|
|
|
|
qw/client_id client_secret refresh_token/; |
49
|
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
0
|
croak <
|
51
|
|
|
|
|
|
|
If your credentials are missing the refresh_token - consider removing the auth at |
52
|
|
|
|
|
|
|
https://myaccount.google.com/permissions as The oauth2 server will only ever mint one refresh |
53
|
|
|
|
|
|
|
token at a time, and if you request another access token via the flow it will operate as if |
54
|
|
|
|
|
|
|
you only asked for an access token. |
55
|
|
|
|
|
|
|
MISSINGCREDS |
56
|
0
|
|
|
|
|
0
|
my $user = $self->user; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
0
|
my $new_token = $self->refresh_user_token(\%p); |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
0
|
$self->tokensfile->set("gapi/tokens/$user/access_token", $new_token); |
61
|
0
|
|
|
|
|
0
|
return $new_token; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub get_token_emails_from_storage { |
65
|
0
|
|
|
0
|
0
|
0
|
my ($self) = @_; |
66
|
0
|
|
|
|
|
0
|
my $tokens = $self->get_from_storage('tokens'); |
67
|
0
|
|
|
|
|
0
|
return [keys %$tokens]; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub get_from_storage { |
72
|
8
|
|
|
8
|
1
|
114
|
my ($self, $key) = @_; |
73
|
8
|
100
|
|
|
|
32
|
if ($key =~ /_token/) { |
74
|
2
|
|
|
|
|
8
|
return $self->tokensfile->get("gapi/tokens/${\$self->user}/$key"); |
|
2
|
|
|
|
|
14
|
|
75
|
|
|
|
|
|
|
} else { |
76
|
6
|
|
|
|
|
32
|
return $self->tokensfile->get("gapi/$key"); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub get_scopes_from_storage_as_array { |
81
|
0
|
|
|
0
|
0
|
0
|
carp |
82
|
|
|
|
|
|
|
'get_scopes_from_storage_as_array is being deprecated, please use the more succint scopes accessor'; |
83
|
0
|
|
|
|
|
0
|
return $_[0]->scopes; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# NOTE - the scopes are stored as a space seperated list, and this method |
87
|
|
|
|
|
|
|
# returns an arrayref |
88
|
|
|
|
|
|
|
# |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub scopes { |
92
|
2
|
|
|
2
|
1
|
6
|
my ($self) = @_; |
93
|
2
|
|
|
|
|
22
|
return [split / /, $self->tokensfile->get('gapi/scopes')]; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
9011; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |