diff --git a/utils/lib/azure.js b/utils/lib/azure.js index e9eaff6294..6b717cbca9 100644 --- a/utils/lib/azure.js +++ b/utils/lib/azure.js @@ -1,17 +1,14 @@ // lib/azure.js +import { DefaultAzureCredential } from "@azure/identity"; //import { getCache, setCache } from "./cache"; export async function getAuthToken() { - if (process.env.AZURE_USE_MANAGED_IDENTITY != "true") { - return ""; - } - const { ManagedIdentityCredential } = require("@azure/identity"); let cachedToken = process.env.AUTH_TOKEN ? JSON.parse(process.env.AUTH_TOKEN) : ''; if (!cachedToken || cachedToken.expiresOnTimestamp < Date.now()) { - let cachedCredential = new ManagedIdentityCredential(); + let cachedCredential = new DefaultAzureCredential(); cachedToken = await cachedCredential.getToken("https://cognitiveservices.azure.com/.default"); process.env.AUTH_TOKEN = JSON.stringify(cachedToken); return cachedToken; @@ -19,3 +16,4 @@ export async function getAuthToken() { // console.log("cachedToken from memory", cachedToken); return process.env.AUTH_TOKEN ? JSON.parse(process.env.AUTH_TOKEN) : '';; } + \ No newline at end of file