Skip to content

Commit

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

This reverts commit 9aaf6b0.
  • Loading branch information
andychase committed Oct 2, 2024
1 parent 9aaf6b0 commit 2b73c33
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions utils/lib/azure.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
// 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;
}
// console.log("cachedToken from memory", cachedToken);
return process.env.AUTH_TOKEN ? JSON.parse(process.env.AUTH_TOKEN) : '';;
}

0 comments on commit 2b73c33

Please sign in to comment.