Skip to content

Commit 4996c47

Browse files
committed
Standardize logging of API call results in authentication examples
1 parent 9946dae commit 4996c47

File tree

4 files changed

+11
-14
lines changed

4 files changed

+11
-14
lines changed

authentication/oauth-authorization-code/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ app.get("/callback", async (req, res) => {
4949

5050
// Exchange the short-lived authorization code for a long-lived access token.
5151
const token = await getAccessToken(req.query.code);
52-
console.log(`Authorization code ${req.query.code} successfully exchanged for access token:`, token);
52+
console.log(`Successfully exchanged authorization code ${req.query.code} for access token:`, token.access_token);
5353

5454
// Test the new token by making an authenticated call to the API.
5555
const userData = await getUserInfo(token.access_token);

authentication/oauth-client-credentials/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import fs from "fs";
1515
try {
1616
// Get a new access token using client credentials authentication.
1717
const token = await getAccessToken();
18+
console.log(`Successfully obtained a new access token:`, token.access_token);
1819

1920
// Test the new token by making an authenticated call to the API.
2021
const userData = await getUserInfo(token.access_token);

authentication/personal-access-token/cc-pat.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ export async function createNewPAT(totp) {
8383
}
8484

8585
/**
86-
* Get list of Personal Access Tokens (PATs), using a bearer token (client credentials.
86+
* Get list of Personal Access Tokens (PATs), using an existing PAT.
8787
*/
8888

89-
export async function getMyPATs(accessToken) {
89+
export async function getUserPATs(accessToken) {
9090
try {
9191
const response = await axios.request({
9292
method: "GET",

authentication/personal-access-token/index.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Dependencies.
33
*/
44

5-
import { createNewPAT, getAuthenticationMethods, getMyPATs } from "./cc-pat.js";
5+
import { createNewPAT, getAuthenticationMethods, getUserPATs } from "./cc-pat.js";
66
import fs from "fs";
77

88
(async () => {
@@ -30,17 +30,13 @@ import fs from "fs";
3030
totp.OTPMethodId = totpCheck.id;
3131
}
3232

33-
// Create a PAT.
34-
const newPAT = await createNewPAT(totp);
33+
// Get a new Personal Access Token (PAT).
34+
const token = await createNewPAT(totp);
35+
console.log("Successfully obtained a new Personal Access Token (PAT):", token.accessToken);
3536

36-
if (newPAT.accessToken) {
37-
console.log("New Personal Access Token (PAT) created with success");
38-
console.debug(newPAT.accessToken);
39-
40-
// Use the newly created PAT to list all PATs for this account.
41-
console.log("List of available PATs");
42-
console.log(await getMyPATs(newPAT.accessToken));
43-
}
37+
// Test the new token by making an authenticated call to the API.
38+
const userPATs = await getUserPATs(token.accessToken);
39+
console.log("Output from test API call:", userPATs);
4440
} catch (error) {
4541
// Unexpected error.
4642
return;

0 commit comments

Comments
 (0)