line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::SOP::Auth::V1_1; |
2
|
2
|
|
|
2
|
|
66384
|
use 5.008001; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
63
|
|
3
|
2
|
|
|
2
|
|
8
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
52
|
|
4
|
2
|
|
|
2
|
|
14
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
94
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
8
|
use Carp (); |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
26
|
|
9
|
2
|
|
|
2
|
|
959
|
use URI; |
|
2
|
|
|
|
|
6651
|
|
|
2
|
|
|
|
|
48
|
|
10
|
2
|
|
|
2
|
|
755
|
use WebService::SOP::Auth::V1_1::Request::GET; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
53
|
|
11
|
2
|
|
|
2
|
|
703
|
use WebService::SOP::Auth::V1_1::Request::POST; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
58
|
|
12
|
2
|
|
|
2
|
|
772
|
use WebService::SOP::Auth::V1_1::Request::POST_JSON; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
54
|
|
13
|
2
|
|
|
2
|
|
9
|
use WebService::SOP::Auth::V1_1::Util qw(is_signature_valid); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
490
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
10
|
|
|
10
|
1
|
7826
|
my ($class, $args) = @_; |
17
|
10
|
|
100
|
|
|
27
|
$args ||= +{ }; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
do { |
20
|
18
|
100
|
|
|
|
78
|
Carp::croak("Missing required parameter: ${_}") if not $args->{$_}; |
21
|
10
|
|
|
|
|
15
|
} for qw( app_id app_secret ); |
22
|
|
|
|
|
|
|
|
23
|
7
|
100
|
|
|
|
24
|
$args->{time} = time if not $args->{time}; |
24
|
|
|
|
|
|
|
|
25
|
7
|
|
|
|
|
21
|
bless $args, $class; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
1
|
1
|
11
|
sub app_id { $_[0]->{app_id} } |
29
|
11
|
|
|
11
|
1
|
69
|
sub app_secret { $_[0]->{app_secret} } |
30
|
12
|
|
|
12
|
1
|
47
|
sub time { $_[0]->{time} } |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub create_request { |
33
|
6
|
|
|
6
|
1
|
461
|
my ($self, $type, $uri, $params) = @_; |
34
|
6
|
50
|
|
|
|
27
|
$uri = URI->new($uri) if not ref $uri; |
35
|
6
|
|
|
|
|
4292
|
my $request_maker = "WebService::SOP::Auth::V1_1::Request::${type}"; |
36
|
6
|
|
|
|
|
24
|
$request_maker->create_request( |
37
|
|
|
|
|
|
|
$uri, |
38
|
|
|
|
|
|
|
{ %$params, time => $self->time }, |
39
|
|
|
|
|
|
|
$self->app_secret, |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub verify_signature { |
44
|
4
|
|
|
4
|
1
|
148
|
my ($self, $sig, $params) = @_; |
45
|
4
|
|
|
|
|
6
|
is_signature_valid($sig, $params, $self->app_secret, $self->time); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
49
|
|
|
|
|
|
|
__END__ |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=encoding utf-8 |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 NAME |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
WebService::SOP::Auth::V1_1 - SOP version 1.1 authentication module |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 SYNOPSIS |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
use WebService::SOP::Auth::V1_1; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
When making a GET request to API: |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $auth = WebService::SOP::Auth::V1_1->new({ |
64
|
|
|
|
|
|
|
app_id => '1', |
65
|
|
|
|
|
|
|
app_secret => 'hogehoge', |
66
|
|
|
|
|
|
|
}); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $req = $auth->create_request( |
69
|
|
|
|
|
|
|
GET => 'https://<API_HOST>/path/to/endpoint' => { |
70
|
|
|
|
|
|
|
hoge => 'hoge', |
71
|
|
|
|
|
|
|
fuga => 'fuga', |
72
|
|
|
|
|
|
|
}, |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
#=> HTTP::Request object |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my $res = LWP::UserAgent->new->request($req); |
77
|
|
|
|
|
|
|
#=> HTTP::Response object |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
When embedding JavaScript URL in page: |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
<script src="<: $req.uri.as_string :>"></script> |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 DESCRIPTION |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
WebService::SOP::Auth::V1_1 is an authentication module |
86
|
|
|
|
|
|
|
for L<SOP|http://console.partners.surveyon.com/> version 1.1 |
87
|
|
|
|
|
|
|
by L<Research Panel Asia, Inc|http://www.researchpanelasia.com/>. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 METHODS |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 new( \%options ) |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Creates a new instance. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Possible options: |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=over 4 |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item C<app_id> |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
(Required) Your C<app_id>. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item C<app_secret> |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
(Required) Your C<app_secret>. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item C<time> |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
(Optional) POSIX time. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=back |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head2 app_id |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Gets C<app_id> configured to instance. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 app_secret |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Gets C<app_secret> configured to instance. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 time |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Gets C<time> configured to instance. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 create_request( $type, $uri, $params ) |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Creates a new L<HTTP::Request> object for API request. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 verify_signature( $sig, $params ) |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Verifies if request signature is valid. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 SEE ALSO |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
L<WebService::SOP::Auth::V1_1::Util> |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Research Panel Asia, Inc. website L<http://www.researchpanelasia.com/> |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 LICENSE |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Copyright (C) Research Panel Asia, Inc. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
144
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 AUTHOR |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
yowcowvg E<lt>yoko_ohyama [ at ] voyagegroup.comE<gt> |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |
151
|
|
|
|
|
|
|
|