| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::Google::DataAPI::Auth::ClientLogin::Multiple; |
|
2
|
1
|
|
|
1
|
|
81043
|
use Any::Moose; |
|
|
1
|
|
|
|
|
20034
|
|
|
|
1
|
|
|
|
|
5
|
|
|
3
|
1
|
|
|
1
|
|
837
|
use Net::Google::AuthSub; |
|
|
1
|
|
|
|
|
17982
|
|
|
|
1
|
|
|
|
|
29
|
|
|
4
|
1
|
|
|
1
|
|
408
|
use Text::Glob; |
|
|
1
|
|
|
|
|
548
|
|
|
|
1
|
|
|
|
|
326
|
|
|
5
|
|
|
|
|
|
|
with 'Net::Google::DataAPI::Role::Auth'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has account_type => ( is => 'ro', isa => 'Str', required => 1, default => 'HOSTED_OR_GOOGLE' ); |
|
10
|
|
|
|
|
|
|
has source => ( is => 'ro', isa => 'Str', required => 1, default => __PACKAGE__ ); |
|
11
|
|
|
|
|
|
|
has username => ( is => 'ro', isa => 'Str', required => 1 ); |
|
12
|
|
|
|
|
|
|
has password => ( is => 'ro', isa => 'Str', required => 1 ); |
|
13
|
|
|
|
|
|
|
has services => ( is => 'ro', isa => 'HashRef', required => 1 ); |
|
14
|
|
|
|
|
|
|
has tokens => ( is => 'rw', isa => 'HashRef', default => sub { +{} }); |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub sign_request { |
|
17
|
7
|
|
|
7
|
0
|
11502
|
my ($self, $req, $host) = @_; |
|
18
|
7
|
|
66
|
|
|
29
|
$host ||= $req->uri->host; |
|
19
|
7
|
|
100
|
|
|
285
|
$self->tokens->{$host} ||= $self->_get_auth_params($host); |
|
20
|
5
|
|
|
|
|
181
|
$req->header(@{$self->tokens->{$host}}); |
|
|
5
|
|
|
|
|
29
|
|
|
21
|
5
|
|
|
|
|
214
|
return $req; |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _get_auth_params { |
|
25
|
5
|
|
|
5
|
|
9
|
my ($self, $host) = @_; |
|
26
|
5
|
|
|
|
|
15
|
my $service = $self->services->{$host}; |
|
27
|
5
|
100
|
|
|
|
14
|
unless ($service) { |
|
28
|
2
|
|
|
|
|
2
|
for my $s (grep {$_ =~ m/\*/} keys %{$self->services}) { |
|
|
6
|
|
|
|
|
12
|
|
|
|
2
|
|
|
|
|
10
|
|
|
29
|
|
|
|
|
|
|
Text::Glob::match_glob($s, $host) |
|
30
|
2
|
100
|
66
|
|
|
9
|
and $service = $self->services->{$s} and last; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
} |
|
33
|
5
|
100
|
|
|
|
560
|
$service or confess "service for $host not defined"; |
|
34
|
4
|
|
|
|
|
38
|
my $authsub = Net::Google::AuthSub->new( |
|
35
|
|
|
|
|
|
|
source => $self->source, |
|
36
|
|
|
|
|
|
|
service => $service, |
|
37
|
|
|
|
|
|
|
accountType => $self->account_type, |
|
38
|
|
|
|
|
|
|
_compat => {uncuddled_auth => 1}, #to export docs |
|
39
|
|
|
|
|
|
|
); |
|
40
|
4
|
|
|
|
|
21121
|
my $res = $authsub->login( |
|
41
|
|
|
|
|
|
|
$self->username, |
|
42
|
|
|
|
|
|
|
$self->password, |
|
43
|
|
|
|
|
|
|
); |
|
44
|
4
|
100
|
|
|
|
9085
|
$res->is_success or confess "login for $host failed"; |
|
45
|
3
|
|
|
|
|
41
|
return [ $authsub->auth_params ]; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
49
|
|
|
|
|
|
|
|
|
50
|
1
|
|
|
1
|
|
5
|
no Any::Moose; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
7
|
|
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |
|
53
|
|
|
|
|
|
|
__END__ |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 NAME |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Net::Google::DataAPI::Auth::ClientLogin::Multiple - keeps and sings auth_params for multiple Google Data API domains |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
use Net::Google::DataAPI::Auth::ClientLogin::Multiple; |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $auth = Net::Google::DataAPI::Auth::ClientLogin::Multiple->new( |
|
64
|
|
|
|
|
|
|
username => 'foo.bar@gmail.com', |
|
65
|
|
|
|
|
|
|
password => 'p4ssw0rd', |
|
66
|
|
|
|
|
|
|
services => { |
|
67
|
|
|
|
|
|
|
'docs.google.com' => 'writely', |
|
68
|
|
|
|
|
|
|
'spreadsheets.google.com' => 'wise', |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
); |
|
71
|
|
|
|
|
|
|
my $req = HTTP::Request->new( |
|
72
|
|
|
|
|
|
|
'GET' => 'https://docs.google.com/feeds/default/private/full' |
|
73
|
|
|
|
|
|
|
); |
|
74
|
|
|
|
|
|
|
$auth->sign_request($req); |
|
75
|
|
|
|
|
|
|
# sets $req Authorization header |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$auth->sign_request($req, 'spreadsheets.google.com'); |
|
78
|
|
|
|
|
|
|
# set authorization header for 'spreadsheets.google.com', not for 'docs.google.com'. |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
This module keeps and sings auth_params for multiple google Data API domains. |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 AUTHOR |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Nobuo Danjou E<lt>danjou@soffritto.orgE<gt> |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
L<Net::Google::AuthSub> |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
L<Net::Google::DataAPI> |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
L<http://code.google.com/intl/en/apis/accounts/docs/AuthForInstalledApps.html> |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
L<http://code.google.com/intl/en/apis/gdata/faq.html#clientlogin> |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 LICENSE |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
101
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |