line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Launchpad; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
1
|
|
|
1
|
|
617
|
$Net::Launchpad::AUTHORITY = 'cpan:ADAMJS'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
$Net::Launchpad::VERSION = '1.0.5'; |
6
|
|
|
|
|
|
|
# ABSTRACT: Launchpad.net Authentication |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
195
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Function::Parameters; |
10
|
|
|
|
|
|
|
use Mojo::UserAgent; |
11
|
|
|
|
|
|
|
use Mojo::URL; |
12
|
|
|
|
|
|
|
use Mojo::Parameters; |
13
|
|
|
|
|
|
|
use Data::Dumper::Concise; |
14
|
|
|
|
|
|
|
use namespace::autoclean; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has staging => (is => 'ro', isa => 'Int', default => 0); |
18
|
|
|
|
|
|
|
has consumer_key => (is => 'ro', isa => 'Str'); |
19
|
|
|
|
|
|
|
has callback_uri => (is => 'ro', isa => 'Str'); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has ua => ( |
22
|
|
|
|
|
|
|
is => 'ro', |
23
|
|
|
|
|
|
|
isa => 'Mojo::UserAgent', |
24
|
|
|
|
|
|
|
default => method { |
25
|
|
|
|
|
|
|
my $ua = Mojo::UserAgent->new; |
26
|
|
|
|
|
|
|
$ua->transactor->name("Net::Salesforce"); |
27
|
|
|
|
|
|
|
return $ua; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
has nonce => (is => 'ro', isa => 'Str', builder => '_build_nonce'); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
method _build_nonce { |
35
|
|
|
|
|
|
|
my @a = ('A' .. 'Z', 'a' .. 'z', 0 .. 9); |
36
|
|
|
|
|
|
|
my $nonce = ''; |
37
|
|
|
|
|
|
|
for (0 .. 31) { |
38
|
|
|
|
|
|
|
$nonce .= $a[rand(scalar(@a))]; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
return $nonce; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
has params => (is => 'rw', isa => 'HashRef', builder => '_build_params'); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
method _build_params { |
47
|
|
|
|
|
|
|
return { |
48
|
|
|
|
|
|
|
oauth_callback => $self->callback_uri, |
49
|
|
|
|
|
|
|
oauth_consumer_key => $self->consumer_key, |
50
|
|
|
|
|
|
|
oauth_version => '1.0a', |
51
|
|
|
|
|
|
|
oauth_signature_method => 'PLAINTEXT', |
52
|
|
|
|
|
|
|
oauth_signature => '&', |
53
|
|
|
|
|
|
|
oauth_token => undef, |
54
|
|
|
|
|
|
|
oauth_token_secret => undef, |
55
|
|
|
|
|
|
|
oauth_timestamp => time, |
56
|
|
|
|
|
|
|
oauth_nonce => $self->nonce |
57
|
|
|
|
|
|
|
}; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
method api_host { |
61
|
|
|
|
|
|
|
return Mojo::URL->new('https://launchpad.net/') unless $self->staging; |
62
|
|
|
|
|
|
|
return Mojo::URL->new('https://staging.launchpad.net'); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
method request_token_path { |
66
|
|
|
|
|
|
|
return $self->api_host->path('+request-token'); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
method access_token_path { |
70
|
|
|
|
|
|
|
return $self->api_host->path('+access-token'); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
method authorize_token_path { |
74
|
|
|
|
|
|
|
return $self->api_host->path('+authorize-token'); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
method request_token { |
78
|
|
|
|
|
|
|
my $tx = |
79
|
|
|
|
|
|
|
$self->ua->post( |
80
|
|
|
|
|
|
|
$self->request_token_path->to_string => form => $self->params); |
81
|
|
|
|
|
|
|
die $tx->res->body unless $tx->success; |
82
|
|
|
|
|
|
|
my $params = Mojo::Parameters->new($tx->res->body); |
83
|
|
|
|
|
|
|
my $token = $params->param('oauth_token'); |
84
|
|
|
|
|
|
|
my $secret = $params->param('oauth_token_secret'); |
85
|
|
|
|
|
|
|
return ($token, $secret); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
method authorize_token($token, $token_secret) { |
89
|
|
|
|
|
|
|
$self->params->{oauth_token} = $token; |
90
|
|
|
|
|
|
|
$self->params->{oauth_token_secret} = $token_secret; |
91
|
|
|
|
|
|
|
my $url = $self->authorize_token_path->query($self->params); |
92
|
|
|
|
|
|
|
return $url->to_string; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
method access_token($token, $secret) { |
96
|
|
|
|
|
|
|
$self->params->{oauth_token} = $token; |
97
|
|
|
|
|
|
|
$self->params->{oauth_token_secret} = $secret; |
98
|
|
|
|
|
|
|
$self->params->{oauth_signature} = |
99
|
|
|
|
|
|
|
'&' . $secret; |
100
|
|
|
|
|
|
|
my $tx = |
101
|
|
|
|
|
|
|
$self->ua->post( |
102
|
|
|
|
|
|
|
$self->access_token_path->to_string => form => $self->params); |
103
|
|
|
|
|
|
|
die $tx->res->body unless $tx->success; |
104
|
|
|
|
|
|
|
my $params = Mojo::Parameters->new($tx->res->body); |
105
|
|
|
|
|
|
|
print Dumper($params); |
106
|
|
|
|
|
|
|
return ($params->param('oauth_token'), $params->param('oauth_token_secret')); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
110
|
|
|
|
|
|
|
1; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
__END__ |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=pod |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=encoding UTF-8 |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 NAME |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Net::Launchpad - Launchpad.net Authentication |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 VERSION |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
version 1.0.5 |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 B<staging> |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Boolean to interact with staging server or production. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 B<ua> |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
A L<Mojo::UserAgent>. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 B<json> |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
A L<Mojo::JSON>. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 B<consumer_key> |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Holds the string that identifies your application. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
$lp->consumer_key('my-app-name'); |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 B<callback_uri> |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Callback url to redirect use back to once authenticated. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 B<nonce> |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Nonce |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 B<params> |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
OAuth 1.0a parameters used in request, authenticate, and access |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 METHODS |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 B<api_host> |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Hostname used for authentication |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head2 B<request_token_path> |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
OAuth Request token url |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 B<access_token_path> |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
OAuth Access token url |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head2 B<authorize_token_path> |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
OAuth Authorize token url |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 B<request_token> |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Perform the request-token request |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 B<authenticate_token> |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Perform the authentication request |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head2 B<access_token> |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Perform the access token request |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 AUTHOR |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Adam Stokes <adamjs@cpan.org> |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
This software is copyright (c) 2014 by Adam Stokes. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
197
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=cut |