Add SHA-256 hash logging for access tokens in auth-test and interactive-login scripts
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import { ClientSecretCredential } from "@azure/identity";
|
import { ClientSecretCredential } from "@azure/identity";
|
||||||
import { config } from "../config.js";
|
import { config } from "../config.js";
|
||||||
|
import { createHash } from "crypto";
|
||||||
|
|
||||||
// We need to wrap the async code in an IIFE
|
// We need to wrap the async code in an IIFE
|
||||||
// Check, authentication using @azure/identity requires a client secret.
|
// Check, authentication using @azure/identity requires a client secret.
|
||||||
@@ -19,6 +20,9 @@ if (config.clientSecret) {
|
|||||||
);
|
);
|
||||||
if (token) {
|
if (token) {
|
||||||
console.log("Authentication with client secret successful.");
|
console.log("Authentication with client secret successful.");
|
||||||
|
const hash = createHash("sha256").update(token.token).digest("hex");
|
||||||
|
console.log("SHA-256 hash of access token:", hash);
|
||||||
|
console.log("Token expires on:", new Date(token.expiresOnTimestamp).toISOString());
|
||||||
} else {
|
} else {
|
||||||
console.error("Authentication with client secret failed.");
|
console.error("Authentication with client secret failed.");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
import { loginInteractive } from "../src/auth.js";
|
import { loginInteractive } from "../src/auth.js";
|
||||||
import { config } from "../public-config.js";
|
import { config } from "../public-config.js";
|
||||||
|
import { createHash } from "crypto";
|
||||||
|
|
||||||
const scopes = ["https://management.azure.com/.default"];
|
const scopes = ["https://management.azure.com/.default"];
|
||||||
|
|
||||||
@@ -17,5 +20,9 @@ try {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Access token acquired:");
|
console.log("Access token acquired.");
|
||||||
//console.log(token.accessToken);
|
|
||||||
|
// Print SHA-256 hash of the access token for verification purposes
|
||||||
|
const hash = createHash("sha256").update(token.accessToken).digest("hex");
|
||||||
|
console.log("SHA-256 hash of access token:", hash);
|
||||||
|
console.log("Token expires on:", token.expiresOn);
|
||||||
|
|||||||
Reference in New Issue
Block a user