How to get idtoken in MS teams
Hi,
I am developing a chatbot on Teams framework. Regarding to customer request I need to call and external REST API on intranet and reply back to bot as an answer. To achieve this flow I am able to create accessToken through https://login.microsoftonline.com but it doesn't have a id token. To be able to get id token I am making another request to https://login.microsoftonline.com with Authorization code grant type. But it returns error below;
[onTurnError] unhandled error: InteractionRequiredAuthError: invalid_grant: AADSTS9002313: Invalid request. Request is malformed or invalid. Trace ID: a0da45bd-aba3-4626-bb8d-90eb1b7f0100 Correlation ID: bc6bd2fa-d520-4511-a912-b339239713b2 Timestamp: 2025-04-19 15:27:44Z
Please note that I am supplying access code that I created by acquireTokenByClientCredential method to acquireTokenByCode method. How can I get id token? Can anybody help me?
Please find the code below;
const msalConfig = {
auth: {
clientId: "50254559-5530-40d1-a91b-4cd42e9dbb63",
authority: "https://login.microsoftonline.com/20e81a44-49c5-46fe-bdbf-fd5d0b0342b1",
clientSecret: "xxxxxxxxxxxx",
},
system: {
loggerOptions: {
loggerCallback(loglevel, message, containsPii) {
console.log(message);
},
piiLoggingEnabled: false,
logLevel: 3,
}
}
}
var request = {
scopes: [ 'https://graph.microsoft.com/.default' ]
};
var client = new msal.ConfidentialClientApplication(msalConfig);
var response = await client.acquireTokenByClientCredential(request);
const accessToken = response["accessToken"]
var request1 = {
code: accessToken,
scopes: ["openid", "profile", "email"],
redirectUri: "https://login.microsoftonline.com/20e81a44-49c5-46fe-bdbf-fd5d0b0342b1/oauth2/v2.0/authorize"
};
var response1 = await client.acquireTokenByCode(request1);