-
Notifications
You must be signed in to change notification settings - Fork 9
/
client.js
55 lines (48 loc) · 1.1 KB
/
client.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
const axios = require('axios');
/**
* Please add `auth0-secret.json` for your credentials
* @example
* ```json
* {
* "client_id": "{CLIENT_ID}",
* "client_secret": "{CLIENT_SECRET}",
* "audience": "http://localhost:3000/ping"
* }
* ```
*/
const secrets = require('./auth0-secret');
/**
* Request an access token using client credentials
*/
const tokenReq = {
method: 'POST',
url: 'https://apitoday.auth0.com/oauth/token',
headers: {'content-type': 'application/json'},
responseType: 'json',
data: {
...secrets,
// eslint-disable-next-line @typescript-eslint/naming-convention
grant_type: 'client_credentials',
scope: 'greet',
},
};
async function main() {
let res = await axios(tokenReq);
console.log(res.data);
/**
* Now try to run the /greet api using the access token
*/
const greetReq = {
method: 'GET',
url: 'http://localhost:3000/greet',
headers: {
authorization: `Bearer ${res.data.access_token}`,
},
};
res = await axios(greetReq);
console.log(res.data);
}
main().catch((err) => {
console.error(err);
process.exit(1);
});