Files
azure-node-playground/bin/auth-test.js

29 lines
844 B
JavaScript

import { ClientSecretCredential } from "@azure/identity";
import { config } from "../config.js";
// 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.appId,
config.clientSecret,
);
const token = await credential.getToken(
"https://management.azure.com/.default",
);
if (token) {
console.log("Authentication with client secret successful.");
} 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.",
);
}