pnp / generator-teams

A Yeoman Generator for Microsoft Teams
https://pnp.github.io/generator-teams
MIT License
428 stars 112 forks source link

Bug report: Unable to get access token from search messaging extension #327

Closed ejazhussain closed 2 years ago

ejazhussain commented 2 years ago

Description

I am trying to call graph API from the Search messaging extension. When executing the following code, it throws an error Error: BotFrameworkAdapter.processActivity(): 500 ERROR. see attachment

         const adapter: any = context.adapter;
        const magicCode = (query.state && Number.isInteger(Number(query.state))) ? query.state : '';        
        const tokenResponse = await adapter.getUserToken(context, this.connectionName, magicCode);

error

authentication-error

Steps to reproduce

  1. Create a search messaging extension app using generator-teams@4.0.1
  2. Create Azure bot and configure auth connection to access Graph API
  3. Add the following code within the query method to authenticate the user
 const adapter: any = context.adapter;
        const magicCode = (query.state && Number.isInteger(Number(query.state))) ? query.state : '';        
        const tokenResponse = await adapter.getUserToken(context, this.connectionName, magicCode);

        if (!tokenResponse || !tokenResponse.token) {
            // There is no token, so the user has not signed in yet.
            // Retrieve the OAuth Sign in Link to use in the MessagingExtensionResult Suggested Actions
            const signInLink = await adapter.getSignInLink(context, this.connectionName);
            let composeExtension: MessagingExtensionResult = {
                type: 'config',
                suggestedActions: {
                    actions: [{
                        title: 'Sign in as user',
                        value: signInLink,
                        type: ActionTypes.OpenUrl
                    }]
                }
            };
            return Promise.resolve(composeExtension);
        }

Expected results

In case, If the user has not logged in, it should display a login adaptive card to the user

Actual results

I am getting the following error

error

Project you experience issues with

generator-teams

generator version

4.

build tools version

4.0.1

nodejs version

v14.15.0

npm version

6.14.8

Operating system (environment)

Windows

Additional Info

No response

ejazhussain commented 2 years ago

The issue was related to setting up the Azure Ad app. It was not related to the Teams generator. Hence closing the bug