Microsoft 应用程序注册 - 如何在应用程序上下文而不是用户上下文中使用 OnlineMeetings.ReadWrite.All 创建会议?

问题描述 投票:0回答:1

我目前在 Azure 门户中注册了一个应用程序。该应用程序设置了一个客户端密钥以及许多 API 权限。这些是 Microsoft Graph 的权限,也是委派的。这就是它的样子,

现在我也为会议设置了一个应用程序角色,如下所示,

考虑到这一点,您可以看到我已从“我的 API”部分添加了应用程序权限,该权限指向我的应用程序注册和“OnlineMeetings.ReadWrite.All”的权限。我的目标是获取访问令牌,以便我的客户端应用程序在运行以下 POST 的同时创建会议,

POST /users/{userId}/onlineMeetings/createOrGet

我的问题是在尝试获取访问令牌时尝试并了解授权范围应该是什么以及授予类型。我尝试将授权范围设置为“offline_access https://graph.microsoft.com/.default”,并将授权类型设置为“client_credentials”,但无济于事。我希望我的客户端应用程序能够代表租户中的任何用户创建会议,而无需用户同意或需要在 Powershell 中设置任何应用程序访问策略。这可以做到吗?

microsoft-graph-api access-token microsoft-graph-teams azureportal
1个回答
0
投票

您不需要设置新的应用程序角色,而是需要添加名为 Application 类型的名为 OnlineMeetings.ReadWrite.All

 的现有 
Microsoft Graph 权限并授予其同意。

我注册了一个 Azure AD 应用程序并授予了 API 权限,如下所示:

enter image description here

请注意,您需要创建应用程序访问策略并授予其访问

Global
的权限,以授权策略中配置的应用程序代表任何用户创建在线会议

我使用以下 PowerShell 命令来安装

MicrosoftTeams
模块并创建应用程序访问策略:

Install-Module -Name MicrosoftTeams -Force -AllowClobber

Import-Module MicrosoftTeams
Connect-MicrosoftTeams

New-CsApplicationAccessPolicy -Identity Sri-Test-policy -AppIds "xxxxxxxxxx" -Description "Allow access to Teams App"

Grant-CsApplicationAccessPolicy -PolicyName Sri-Test-policy -Global

回复:

enter image description here

现在,我通过 Postman 使用客户端凭据流生成了 访问令牌,参数如下:

POST https://login.microsoftonline.com/tenantID/oauth2/v2.0/token
grant_type:client_credentials
client_id: appID
client_secret: secret 
scope: https://graph.microsoft.com/.default

回复:

enter image description here

当我使用此令牌发出以下 POST 请求时,在线会议已成功创建,如下所示:

POST https://graph.microsoft.com/v1.0/users/{userId}/onlineMeetings/createOrGet
Content-Type: application/json

{
  "startDateTime":"2023-07-29T14:30:34.2444915-07:00",
  "endDateTime":"2023-07-29T15:00:34.2464912-07:00",
  "subject":"Sri Demo Online Meeting",
  "externalId": "xxxxxxxxxx",
  "participants": {
        "attendees": [
            {
                "identity": {
                    "user": {
                        "id": "xxxxxxxxxxxxx"
                    }
                },
                "upn": "[email protected]"
            }
        ]
    }
}

回复:

enter image description here

参考: onlineMeeting:createOrGet - Microsoft Graph v1.0 |微软

© www.soinside.com 2019 - 2024. All rights reserved.