line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Salesforce; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
1
|
|
|
1
|
|
22347
|
$Net::Salesforce::AUTHORITY = 'cpan:ADAMJS'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
642
|
use Mojo::Base -base; |
|
1
|
|
|
|
|
9756
|
|
|
1
|
|
|
|
|
7
|
|
7
|
1
|
|
|
1
|
|
682
|
use Mojo::UserAgent; |
|
1
|
|
|
|
|
361467
|
|
|
1
|
|
|
|
|
12
|
|
8
|
1
|
|
|
1
|
|
35
|
use Mojo::URL; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
9
|
1
|
|
|
1
|
|
17
|
use Mojo::Parameters; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
10
|
1
|
|
|
1
|
|
15
|
use Digest::SHA; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
626
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '1.0.0'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has 'key'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has 'secret'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has 'redirect_uri' => 'https://localhost:8081/callback'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has 'api_host' => 'https://na15.salesforce.com/'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has 'access_token_path' => 'services/oauth2/token'; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has 'authorize_path' => 'services/oauth2/authorize'; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has 'scope' => 'api refresh_token'; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has 'response_type' => 'code'; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
has 'params' => sub { |
31
|
|
|
|
|
|
|
my $self = shift; |
32
|
|
|
|
|
|
|
return { |
33
|
|
|
|
|
|
|
client_id => $self->key, |
34
|
|
|
|
|
|
|
client_secret => $self->secret, |
35
|
|
|
|
|
|
|
redirect_uri => $self->redirect_uri, |
36
|
|
|
|
|
|
|
}; |
37
|
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
has 'json' => sub { |
40
|
|
|
|
|
|
|
my $self = shift; |
41
|
|
|
|
|
|
|
my $json = Mojo::JSON->new; |
42
|
|
|
|
|
|
|
return $json; |
43
|
|
|
|
|
|
|
}; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
has 'ua' => sub { |
46
|
|
|
|
|
|
|
my $self = shift; |
47
|
|
|
|
|
|
|
my $ua = Mojo::UserAgent->new; |
48
|
|
|
|
|
|
|
$ua->transactor->name("Net::Salesforce/$VERSION"); |
49
|
|
|
|
|
|
|
return $ua; |
50
|
|
|
|
|
|
|
}; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub verify_signature { |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# TODO: fix verify |
55
|
0
|
|
|
0
|
1
|
|
my ($self, $payload) = @_; |
56
|
0
|
|
|
|
|
|
my $sha = Digest::SHA->new(256); |
57
|
0
|
|
|
|
|
|
$sha->hmac_sha256($self->secret); |
58
|
0
|
|
|
|
|
|
$sha->add($payload->{id}); |
59
|
0
|
|
|
|
|
|
$sha->add($payload->{issued_at}); |
60
|
0
|
|
|
|
|
|
$sha->b64digest eq $payload->{signature}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub refresh { |
64
|
0
|
|
|
0
|
1
|
|
my ($self, $refresh_token) = @_; |
65
|
0
|
|
|
|
|
|
$self->params->{refresh_token} = $refresh_token; |
66
|
0
|
|
|
|
|
|
$self->params->{grant_type} = 'refresh_token'; |
67
|
0
|
|
|
|
|
|
return $self->oauth2; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub password { |
71
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
72
|
0
|
|
|
|
|
|
$self->params->{grant_type} = 'password'; |
73
|
0
|
|
|
|
|
|
return $self->oauth2; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub authenticate { |
77
|
0
|
|
|
0
|
1
|
|
my ($self, $code) = @_; |
78
|
0
|
|
|
|
|
|
$self->params->{code} = $code; |
79
|
0
|
|
|
|
|
|
$self->params->{grant_type} = 'authorization_code'; |
80
|
0
|
|
|
|
|
|
return $self->oauth2; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub authorize_url { |
84
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
85
|
0
|
|
|
|
|
|
$self->params->{response_type} = 'code'; |
86
|
0
|
|
|
|
|
|
my $url = Mojo::URL->new($self->api_host) |
87
|
|
|
|
|
|
|
->path($self->authorize_path) |
88
|
|
|
|
|
|
|
->query($self->params); |
89
|
0
|
|
|
|
|
|
return $url->to_string; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub access_token_url { |
93
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
94
|
0
|
|
|
|
|
|
my $url = Mojo::URL->new($self->api_host)->path($self->access_token_path); |
95
|
0
|
|
|
|
|
|
return $url->to_string; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub oauth2 { |
99
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
my $tx = |
102
|
|
|
|
|
|
|
$self->ua->post($self->access_token_url => form => $self->params); |
103
|
|
|
|
|
|
|
|
104
|
0
|
0
|
|
|
|
|
die $tx->res->body unless $tx->success; |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
my $payload = $self->json->decode($tx->res->body); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# TODO: fix verify signature |
109
|
|
|
|
|
|
|
# die "Unable to verify signature" unless $self->verify_signature($payload); |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
return $payload; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
__END__ |