#!/usr/bin/env node 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. if (config.clientSecret) { console.log("Client secret is set."); // Create the client const credential = new ClientSecretCredential( config.tenantId, config.clientId, config.clientSecret, ); const token = await credential.getToken( "https://management.azure.com/.default", ); 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); } } else { console.warn( "Warning: No client secret generated. Authentication may fail if the application requires a client secret.", ); }