Add SHA-256 hash logging for access tokens in auth-test and interactive-login scripts

This commit is contained in:
2026-01-31 00:09:42 +01:00
parent c733310d69
commit 6f2c7fcd00
2 changed files with 13 additions and 2 deletions

View File

@@ -2,6 +2,7 @@
import { ClientSecretCredential } from "@azure/identity";
import { config } from "../config.js";
import { createHash } from "crypto";
// We need to wrap the async code in an IIFE
// Check, authentication using @azure/identity requires a client secret.
@@ -19,6 +20,9 @@ if (config.clientSecret) {
);
if (token) {
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 {
console.error("Authentication with client secret failed.");
process.exit(1);

View File

@@ -1,5 +1,8 @@
#!/usr/bin/env node
import { loginInteractive } from "../src/auth.js";
import { config } from "../public-config.js";
import { createHash } from "crypto";
const scopes = ["https://management.azure.com/.default"];
@@ -17,5 +20,9 @@ try {
process.exit(1);
}
console.log("Access token acquired:");
//console.log(token.accessToken);
console.log("Access token acquired.");
// 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);