Azure Functions
An Azure service that provides an event-driven serverless compute platform.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
We had generated a token for a managed identity using the following code in Azure Function App -
const { ManagedIdentityCredential } = require('@azure/identity');
module.exports = async function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
const clientId = req.query.clientId;
const resource = req.query.resource;
if (!clientId || !resource) {
context.res = {
status: 400,
body: "Please pass clientId and resource on the query string"
};
return;
}
try {
const credential = new ManagedIdentityCredential(clientId);
const tokenResponse = await credential.getToken(resource);
context.res = {
status: 200,
body: tokenResponse.token
};
} catch (error) {
context.res = {
status: 500,
body: `Error acquiring token: ${error.message}`
};
}
};
This managed identity is added as a federated credential in the App Registration. We use the token generated by the above code to make a call to the endpoint of the app registration ([https://login.microsoftonline.com/