Get Contextual Information for Tabs
发布时间:2026-09-21 | 浏览:1
Access to this page requires authorization. You can try signing in or changing directories .
Access to this page requires authorization. You can try changing directories .
Your tab requires contextual information to display relevant content:
Basic information about the user, team, or company.
Locale and theme information.
The page.id and page.subPageId that identify what is in this tab (known as entityId and subEntityId before TeamsJS v2.0.0).
Context about the user, team, or company can be especially useful when:
You create or associate resources in your app with the specified user or team.
You initiate an authentication flow from Microsoft Entra ID or other identity provider, and you don't require the user to enter their username again.
For more information, see authenticate a user in your Microsoft Teams .
Although this user information can help provide a smooth user experience, you must not use it as proof of identity. For example, an attacker can load your page in a browser and render harmful information or requests.
Access context information
You can access context information in two ways:
Using URL placeholder values .
From the Microsoft Teams JavaScript client library context object.
Get context by inserting URL placeholder values
Use placeholders in your configuration or content URLs. Microsoft Teams replaces the placeholders with the relevant values when determining the actual configuration or content URL. The available placeholders include all fields on the context object. Common placeholders include the following properties:
{page.id} : The developer-defined unique ID for the page defined when first configuring the page . (Known as {entityId} before TeamsJS v2.0.0).
{page.subPageId} : The developer-defined unique ID for the subpage this content points defined when generating a deep link for a specific item within the page. (Known as {subEntityId} before TeamsJS v2.0.0).
{user.loginHint} : A value suitable as a sign in hint for Microsoft Entra ID. This is usually the sign in name of the current user in their home tenant. (Known as {loginHint} before TeamsJS v2.0.0).
{user.userPrincipalName} : The User Principal Name of the current user in the current tenant. (Known as {userPrincipalName} before TeamsJS v2.0.0).
{user.id} : The Microsoft Entra object ID of the current user in the current tenant. (Known as {userObjectId} before TeamsJS v2.0.0).
{app.theme} : The current user interface (UI) theme such as default , dark , or glass , contrast . (Known as {theme} before TeamsJS v2.0.0).
{team.groupId} : The ID of the Microsoft 365 group in which the tab resides. (Known as {groupId} before TeamsJS v2.0.0)
{user.tenant.id} : The Microsoft Entra tenant ID of the current user. (Known as {tid} before TeamsJS v2.0.0).
{app.locale} : The current locale of the user formatted as languageId-countryId , for example en-us . (Known as {locale} before TeamsJS v2.0.0).
The previous {upn} placeholder is now deprecated. For backward compatibility, it's a synonym for {user.loginHint} .
Mobile (Android and iOS) versions of Microsoft Teams support only TeamsJS v1.x.x placeholders.
For example, in your app manifest if you set your tab configurationUrl attribute to "https://www.contoso.com/config?name={user.loginHint}&tenant={user.tenant.id}&group={team.groupId}&theme={app.theme}" and the signed-in user has the following attributes:
Their username is user@example.com .
Their company tenant ID is e2653c-etc .
They're a member of the Microsoft 365 group with ID 00209384-etc .
The user has set their Teams theme to dark .
Teams calls the following URL when configuring the tab:
https://www.contoso.com/config?name=user@example.com&tenant=e2653c-etc&group=00209384-etc&theme=dark
Get context by using the Microsoft Teams JavaScript library
You can also retrieve the context information using the Microsoft Teams JavaScript client library .
The information can be retrieved by calling microsoftTeams.app.getContext().then((context) => {/*...*/}); .
The following code provides an example of context variable:
The information can be retrieved by calling microsoftTeams.getContext(function(context) { /* ... */ }) .
The following code provides an example of context variable:
Equivalent async/await pattern:
Equivalent async/await pattern:
The following table lists commonly used context properties of the context object:
For more information, see Updates to the Context interface and the Context interface API reference.
Retrieve context in private channels
Private channels are in private developer preview only.
When your content page is loaded in a private channel, the data you receive from the getContext call is obfuscated to protect the privacy of the channel.
The following fields are changed when your content page is in a private channel:
team.groupId : Undefined for private channels
team.internalId : Set to the threadId of the private channel
team.displayName : Set to the name of the private channel
sharepointSite.teamSiteUrl : Set to the URL of a distinct, unique SharePoint site for the private channel
sharepointSite.teamSitePath : Set to the path of a distinct, unique SharePoint site for the private channel
sharepointSite.teamSiteDomain : Set to the domain of a distinct, unique SharePoint site domain for the private channel
channel.ownerGroupId : Set to the host team groupId of the private channel
If your page makes use of any of these values, the value of channel.membershipType field must be Private to determine if your page is loaded in a private channel and can respond appropriately.
teamSiteUrl also works well for standard channels. If your page makes use of any of these values, the value of channelType field must be Shared to determine if your page is loaded in a shared channel and can respond appropriately.
Get context in shared channels
When the content UX is loaded in a shared channel, use the data received from getContext call for shared channel changes. If tab makes use of any of the following values, you must populate the channelType field to determine if the tab is loaded in a shared channel, and respond appropriately. For shared channels, the groupId value is null , since the host team's groupId doesn't accurately reflect the true membership of the shared channel. To address this, the hostTeamGroupID and hostTenantID properties are newly added and useful for making Microsoft Graph API calls to retrieve membership. hostTeam refers to the Team that created the shared channel. currentTeam refers to Team that the current user is accessing the shared channel from.
For more information about these concepts and shared channels, see shared channels .
Use the following getContext properties in shared channels:
For more information on shared channels, see shared channels .
Handle theme change
By default, the new Teams client supports light theme for apps in Teams meetings. When the app.theme property in getContext API returns the default value, Teams client is in light theme.
Earlier version of Teams clients only support Dark and Contrast theme for apps in Teams meetings.
You can register your app to be informed if the theme changes by calling microsoftTeams.app.registerOnThemeChangeHandler(function(theme) { /* ... */ }) .
The theme argument in the function is a string with a value of default , dark , glass , or contrast . The AppInfo property in the getContext API supports the glass theme for Teams running on Apple Vision Pro devices.
The following image shows the default theme option in the Teams:
The following image shows the dark theme option in the Teams:
Build tabs for Teams
Design your tab for Microsoft Teams
Enable SSO for tab app
Agents and tab apps for shared and private channels
App manifest schema for Teams
Use dialogs in tabs
Was this page helpful?
Need help with this topic?
Want to try using Ask Learn to clarify or guide you through this topic?
Additional resources
Last updated on 2026-03-02