forked from zamd/introspection-sample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetAsps.js
37 lines (33 loc) · 1018 Bytes
/
getAsps.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
/**
Get App Specific Passwords demo
**/
const jwt = require('jsonwebtoken');
const request = require('superagent-bluebird-promise');
require('dotenv').config();
// used for local testing, never do this in a production env
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
let accessToken;
// authenticate
request
.post(`${process.env.AUTH0_TENANT}/oauth/token`)
.send({
grant_type: 'client_credentials',
client_id: process.env.AUTH0_MGMTAPI_CLIENTID,
client_secret: process.env.AUTH0_MGMTAPI_CLIENTSECRET,
audience: process.env.AUTH0_MGMTAPI_IDENTIFIER
}).then(res => {
accessToken = res.body.access_token;
if (!accessToken) {
throw new Error('Unable to obtain access token');
}
// now we have a token, get the ASPs
return request
.get(`${process.env.AUTH0_MGMTAPI_IDENTIFIER}users/${process.env.AUTH0_USER_ID}/application-passwords`)
.set('Authorization', 'Bearer ' + accessToken)
.send();
}).then(res => {
console.log(res.body);
})
.catch(err => {
console.log(err.body);
});