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