如何在 Microsoft Teams 选项卡中检查用户是否为管理员

How to check whether the user is admin or not in Microsoft Teams tab

我在 Microsoft Teams 上有基于 Angular 的选项卡 运行。

我对如何知道登录用户是否是管理员感兴趣。

到目前为止,我正在尝试使用 https://graph.microsoft.com/v1.0/me/memberOf?$top=5。但我认为这需要一些权限,我不确定如何添加权限?

此外,是否有任何其他方法可以了解使用 Angular 登录 MS Teams 应用程序的用户的角色?

我假设“管理员”是指团队“所有者”。如果是这样,在上下文对象上有一个 userTeamRole 属性,它将包含 Owneruserguest。在 https://docs.microsoft.com/en-us/microsoftteams/platform/tabs/how-to/access-teams-context and https://docs.microsoft.com/en-us/javascript/api/@microsoft/teams-js/microsoftteams.userteamrole?view=msteams-client-js-latest

查看更多

没有“租户管理员”这样的东西,但有些角色会授予您管理员权限。

要知道用户是否是“管理员”,您需要做两件事:

首先您需要使用此请求请求角色列表:

GET https://graph.microsoft.com/v1.0/directoryRoles

documentation is here

在回复中您将看到所有角色。假设您只需要全局管理员。以下是响应示例:

HTTP/1.1 200 OK
Content-type: application/json

{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#directoryRoles",
  "value": [
    {
      "id": "9ed3a0c4-53e1-498c-ab4d-2473476fde14",
      "deletedDateTime": null,
      "description": "Can manage all aspects of Azure AD and Microsoft services that use Azure AD identities.",
      "displayName": "Global Administrator"
    },
    ...data is trunkated...

其次是检索分配给您感兴趣的角色的委托人列表:

GET https://graph.microsoft.com/v1.0/directoryRoles/9ed3a0c4-53e1-498c-ab4d-2473476fde14/members

documentation is here

并检查您的用户是否在列表中。如果它在列表中,则表示它是管理员。

这是一个响应示例:

HTTP/1.1 200 OK
Content-type: application/json
{
  "value": [
    {
      "businessPhones":["000-000-0000"],
      "displayName":"Adele Vance",
      "givenName":"Adele",
      "jobTitle":null,
      "mail":"AdeleV@contoso.com",
      "officeLocation":null,
      "preferredLanguage":"en-US",
      "surname":"Vance",
      "userPrincipalName":"AdeleV@contoso.com"
    }
  ]
}

希望对您有所帮助。