Getting wrong assertion issuer - sts.windows.net instead of login.microsoftonline.com

Devansh Agarwal 20 Reputation points
2024-07-29T06:51:40.9266667+00:00

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/

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,114 questions
Microsoft Entra
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.