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. |
|
|
|
officedev-microsoft-teams-samples-graph-rsc-nodeJs-helper |
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.
- Tab
- RSC Permissions
- Graph
- Tab App in team channel
- Tab App in group chat
- NodeJS version v16.14.2 or Higher Version
- dev tunnel or ngrok latest version or equivalent tunnelling solution
- M365 developer account or access to a Teams account with the appropriate permissions to install an app.
- Teams Toolkit for VS Code
The simplest way to run this sample in Teams is to use Teams Toolkit for Visual Studio Code.
- Ensure you have downloaded and installed Visual Studio Code
- Install the Teams Toolkit extension
- Select File > Open Folder in VS Code and choose this samples directory from the repo
- Using the extension, sign in with your Microsoft 365 account where you have permissions to upload custom apps
- Select Debug > Debug in team channel for RSC permissions or F5 to run the app in a Teams web client
- In the browser that launches, select the Add to a team button to install the app to a team channel
- Click Save to finish the App configureation
- Select Debug > Debug in group chat for RSC permissions to run the app in a Teams web client
- In the browser that launches, select the Add to a chat button to install the app to a group chat
- Click continue when popuping devtunnel dialog
- 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.
-
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 ofauthorization.permissions.resourceSpecific
inappManifest/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 basicUser.Read
permission only. The token used to call Graph API is generated as following. The scope for the token ishttps://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}`;
- Graph RSC
- Upload app manifest file (zip file) to your team.