-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathindex.js
More file actions
27 lines (23 loc) · 775 Bytes
/
index.js
File metadata and controls
27 lines (23 loc) · 775 Bytes
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
/**
* Dependencies.
*/
import { getUserInfo, getAccessToken } from "./client-credentials-flow.js";
import fs from "fs";
(async () => {
// Check for the .env file.
if (fs.existsSync('./.env') === false) {
console.log("Missing .env file. Please follow the steps described in the README.");
return;
}
try {
// Get a new access token using client credentials authentication.
const token = await getAccessToken();
console.log(`Successfully obtained a new access token:`, token.access_token);
// Test the new token by making an authenticated call to the API.
const userData = await getUserInfo(token.access_token);
console.log("Output from test API call:", userData);
} catch (error) {
// Unexpected error.
return;
}
})();