-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth0tools.js
42 lines (41 loc) · 1.47 KB
/
auth0tools.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
var auth0 = require('auth0');
const ManagementClient = auth0.ManagementClient;
module.exports = {
async addAuth0Url(credentials, url) {
if (typeof credentials.Auth0ClientDomain === 'undefined') {
throw new Error('Auth0ClientDomain is required in the credentials parameter');
}
if (typeof credentials.Auth0MgmtApiClientId === 'undefined') {
throw new Error('Auth0MgmtApiClientId is required in the credentials parameter');
}
if (typeof credentials.Auth0MgmtApiSecret === 'undefined') {
throw new Error('Auth0MgmtApiSecret is required in the credentials parameter');
}
if (typeof credentials.Auth0ClientID === 'undefined') {
throw new Error('Auth0ClientID is required in the credentials parameter');
}
if (typeof url === 'undefined') {
throw new Error('url is required');
}
const mgmt = new ManagementClient({
domain: credentials.Auth0ClientDomain,
clientId: credentials.Auth0MgmtApiClientId,
clientSecret: credentials.Auth0MgmtApiSecret,
});
const client = await mgmt.getClient({
client_id: credentials.Auth0ClientID,
});
return mgmt.updateClient(
{
client_id: credentials.Auth0ClientID,
},
{
callbacks: client.callbacks.concat([`${ url }/authenticated`]),
web_origins: client.web_origins.concat([url]),
allowed_logout_urls: client.allowed_logout_urls.concat([url]),
},
).then(result => {
return result;
});
},
};