Cannot access to Azure Graph via BOT MS Teams

48 Views Asked by At

I do this through a bot in MS Teams in TypeScript by initiating a client to Graph Azure:

ERROR. Scopes: User.Read, TeamMember.Read.All, TeamMember.ReadWrite.All, User.Read.All, User.ReadWrite.All, Directory.Read.All, Directory.ReadWrite.All, ChannelMessage.Read.All, AuditLog.Read.All, Directory.AccessAsUser.All, email, Group.ReadWrite.All, openid, profile, User.ReadWrite.All. Error message: null. null.

I do this through a bot in MS Teams in TypeScript by initiating a client to Graph Azure:

export const msalConfig = {
    auth: {
        clientId: process.env.AAD_APP_CLIENT_ID,
        authority: `https://login.microsoftonline.com/${process.env.AAD_APP_TENANT_ID}`,
        tenantId: process.env.AAD_APP_TENANT_ID,
        clientSecret: process.env.SECRET_AAD_APP_CLIENT_SECRET,
        redirectUri: 'http://localhost:53000/',
    },
}

export default msalConfig

...

const credentialsApi = new InteractiveBrowserCredential(msalConfig.auth)

console.log(credentialsApi)

// Initialize the Graph client
const graphClient = Client.initWithMiddleware({
    authProvider: {
        async getAccessToken() {
            // Acquire token using ClientSecretCredential
            const token = await credentialsApi.getToken([
                'User.Read',
                'TeamMember.Read.All',
                'TeamMember.ReadWrite.All',
                'User.Read.All',
                'User.ReadWrite.All',
                'Directory.Read.All',
                'Directory.ReadWrite.All',
                'ChannelMessage.Read.All',
                'AuditLog.Read.All',
                'Directory.AccessAsUser.All',
                'email',
                'Group.ReadWrite.All',
                'openid',
                'profile',
                'User.ReadWrite.All',
            ])
            return token?.token || ''
        },
    },
})

...call api

        const b = context.activity.channelData


        const messagess = await graphClient.api(`/teams/${b.team.id}/channels/${b.channel.id}/messages?top=3`).get()
        if (messagess) {
            await context.sendActivity(`Here you can find messages ${messagess}`)
        }

Get from bot in MS Teams:

bot response

RedirectUri:

response from RedirectUri

I made sure of the configuration in Azure (application registration):

Redirect URIs

settings

permissions

expose API

manifest.json:


    "validDomains": ["${{BOT_DOMAIN}}", "*.botframework.com", "${{TAB_DOMAIN}}"],
    "webApplicationInfo": {
        "id": "${{AAD_APP_CLIENT_ID}}",
        "resource": "api://${{TAB_DOMAIN}}/botid-${{AAD_APP_CLIENT_ID}}"
    }

I have no idea what I can do anymore to get the bot to read data from the Graph API....

Does anyone have any idea how to fix this?

0

There are 0 best solutions below