Skip to content

Latest commit

 

History

History
page_type description products languages extensions urlFragment
sample
This sample demonstrates how to configure Resource Specific Consent (RSC) permissions in a Teams app manifest and use them to call Microsoft Graph, allowing you to observe real API responses in both team channels and group chats.
office-teams
nodejs
contentType createdDate
samples
29/04/2024 01:38:26 PM
officedev-microsoft-teams-samples-graph-rsc-nodeJs-helper

Resource specific consent with Graph API

This sample application showcases how to configure Resource Specific Consent permissions in a Microsoft Teams app manifest to facilitate calls to Microsoft Graph. It includes features for installation in team channels and group chats, allowing users to observe real API responses based on granted permissions, while leveraging the Teams Toolkit for easy setup and debugging.

Included Features

  • Tab
  • RSC Permissions
  • Graph
  • Tab App in team channel
  • Tab App in group chat

Prerequisites

Interaction with app

graph RSC helper

Run the app (Using Teams Toolkit for Visual Studio Code)

The simplest way to run this sample in Teams is to use Teams Toolkit for Visual Studio Code.

  1. Ensure you have downloaded and installed Visual Studio Code
  2. Install the Teams Toolkit extension
  3. Select File > Open Folder in VS Code and choose this samples directory from the repo
  4. Using the extension, sign in with your Microsoft 365 account where you have permissions to upload custom apps

Debug in team channel

  1. Select Debug > Debug in team channel for RSC permissions or F5 to run the app in a Teams web client
  2. In the browser that launches, select the Add to a team button to install the app to a team channel
  3. Click Save to finish the App configureation

Debug in group chat

  1. Select Debug > Debug in group chat for RSC permissions to run the app in a Teams web client
  2. In the browser that launches, select the Add to a chat button to install the app to a group chat
  3. Click continue when popuping devtunnel dialog
  4. Click Save to finish the App configureation

If you do not have permission to upload custom apps (sideloading), Teams Toolkit will recommend creating and using a Microsoft 365 Developer Program account - a free program to get your own dev environment sandbox that includes Teams.

Note

  • Due to the length limit of the RSC permission in manifest, separate permission lists are used for team channel and group chat under the setupManifest folder. Every time, debug launch will load the permissions in corresponding team/chat file and write them into the the section of authorization.permissions.resourceSpecific in appManifest/manifest.json

  • The sample provide several parameters in request url and request body. Parameters in format {...} will be replaced with default value automatically when the request sent. Parameters in format [...] should be replaced by users.

  • The sample collects the tenantId, userId, teamId, channelId and chatId information in views/RSCGraphAPI.ejs using team-js SDK.

  • The sample creates an Aad App using aad.manifest.json with basic User.Read permission only. The token used to call Graph API is generated as following. The scope for the token is https://graph.microsoft.com/.default

// graph/credential.js
const tenantId = process.env.TenantId;
const clientId = process.env.ClientId;
const clientSecret = process.env.ClientSecret;
const credential = new identity.ClientSecretCredential(tenantId, clientId, clientSecret);

// graph/client.js
const token = await credential.getToken(
    "https://graph.microsoft.com/.default"
);
axios.defaults.headers.common["Authorization"] = `Bearer ${token.token}`; 

App review: Overview

Team installation: Overview

Chat installation: Overview

Graph API response: Response

Further Reading.