-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthentication.js
118 lines (109 loc) · 2.69 KB
/
authentication.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
const perform = async (z, bundle) => {
const options = {
url: `https://${ bundle.authData.subdomain }.paycor.com/sts/v1/common/token`,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Accept: 'application/json',
},
params: { 'subscription-key': '{{bundle.authData.subscription_key}}' },
body: {
grant_type: 'refresh_token',
refresh_token: '{{bundle.authData.refresh_token}}',
client_id: '{{bundle.authData.client_id}}',
client_secret: '{{bundle.authData.client_secret}}',
},
};
// z.console.log('options',options)
return z.request(options).then((response) => {
response.throwForStatus();
const results = response.json;
// z.console.log('results',results)
return results;
});
};
const test = async (z, bundle) => {
const options = {
url: `https://${ bundle.authData.subdomain }.paycor.com/v1/legalentities/ActivatedLegalEntityTenantList`,
method: 'GET',
headers: {
Authorization: 'Bearer {{bundle.authData.access_token}}',
'Ocp-Apim-Subscription-Key': '{{bundle.authData.subscription_key}}',
},
};
return z.request(options).then((response) => {
response.throwForStatus();
const results = response.json;
// z.console.log('results',results)
return results;
});
}
module.exports = {
type: 'session',
test: test,
fields: [
{
key: 'subdomain',
label: 'Server',
type: 'string',
required: true,
choices: { 'apis': 'Production', 'apis-sandbox': 'Sandbox' },
default: 'apis',
computed: false,
},
{
computed: false,
key: 'client_id',
required: true,
label: 'Client ID',
type: 'string',
},
{
computed: false,
key: 'client_secret',
required: true,
label: 'Client Secret',
type: 'string',
},
{
computed: false,
key: 'subscription_key',
required: true,
label: 'Subscription Key',
type: 'string',
},
{
computed: false,
key: 'refresh_token',
required: true,
label: 'Refresh Token',
type: 'string',
},
{
computed: false,
key: 'legal_entity_id',
required: true,
label: 'Legal Entity Id',
type: 'string',
helpText: 'LegalEntityId = ClientID',
},
{
computed: false,
key: 'tenant_id',
required: true,
label: 'Tenant ID',
type: 'string',
helpText: 'TenantId = CompanyId',
},
{
computed: true,
key: 'access_token',
required: false,
type: 'string'
},
],
sessionConfig: {
perform: perform,
},
connectionLabel: '{{bundle.authData.subdomain}}.paycor.com'
};