Skip to content

Commit

Permalink
Reapply "Changes to make api work and also better errors for no manag…
Browse files Browse the repository at this point in the history
…ed identity"

This reverts commit 2b73c33.
  • Loading branch information
andychase committed Oct 8, 2024
1 parent 33fec2d commit cbbdac9
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions utils/lib/azure.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
// 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 DefaultAzureCredential();
let cachedCredential = new ManagedIdentityCredential();
cachedToken = await cachedCredential.getToken("https://cognitiveservices.azure.com/.default");
process.env.AUTH_TOKEN = JSON.stringify(cachedToken);
return cachedToken;
}
// console.log("cachedToken from memory", cachedToken);
return process.env.AUTH_TOKEN ? JSON.parse(process.env.AUTH_TOKEN) : '';;
}

0 comments on commit cbbdac9

Please sign in to comment.