'Teams bot SSO without dialogs framework. Invalid x5t claim

I'm following this tutorial:

The bot worked as expected. But I would like not to use the dialog framework. I'm having trouble adapting the model.

In the personal scope I reply to a message with an oauth card:

const oauthCard = await CardFactory.oauthCard(SsoConnectionName, undefined, undefined, undefined, {
  id: 'random65jHf9276hDy47',
  uri: `api://botid-${MicrosoftAppId}`
})
await context.sendActivity(MessageFactory.attachment(oauthCard))

so i get the token on the handler

handleTeamsSigninTokenExchange(context, query) {
  if (context?.activity?.name === tokenExchangeOperationName) {
    console.dir(context?.activity?.value)
    token = context?.activity?.value?.token
  }
}

What am I supposed to do with this token? I get the Invalid x5t claim error when I try to use microsoft client like this:

msGraphClient = microsoft.Client.init({
  debugLogging: true,
  authProvider: done => {
    done(null, token)
  }
})
// on message 'whoiam'
const me = await msGraphClient.api("me").get()

Is this the correct token? How do I initialize the Microsoft Graph client with this token?

My repo sample: https://github.com/itacirgabral/teamsbotSSOdemo/blob/nodialog/nodialogs.js



Solution 1:[1]

You can use below code snippet for initializing the Graph Client:

// Get an Authenticated Microsoft Graph client using the token issued to the user.
    this.graphClient = Client.init({
        authProvider: (done) => {
            done(null, this._token); // First parameter takes an error if you can't get an access token.
        }
    });

Refence sample link: https://github.com/OfficeDev/Microsoft-Teams-Samples/blob/main/samples/app-sso/nodejs/server/models/simpleGraphClient.js

https://github.com/OfficeDev/Microsoft-Teams-Samples/blob/main/samples/app-sso/nodejs/server/api/appController.js

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ChetanSharma-msft