gpt4 book ai didi

c# - 如何使用 Microsoft Graph 创建 Microsoft Teams session 作为应用程序?

转载 作者:行者123 更新时间:2023-12-05 02:41:28 28 4
gpt4 key购买 nike

我正在开发一个日历 Web 应用程序,我想在其中创建 Teams session 并将 session (加入 URL)添加到约会。

由于并非所有用户都通过 Microsoft OAuth 2.0 登录进行登录,因此我必须在服务器端(作为应用程序)创建团队 session 。我为我的应用程序创建了一个 Azure 应用程序注册,并为其分配了 API 权限“OnlineMeetings.ReadWrite.All”(应用程序)。我的应用程序正在使用客户端凭据身份验证流程。

现在的实际问题:

我尝试根据此 Microsoft 文档创建 onlineMeeting: Create onlineMeeting

文档说,我必须创建一个“应用程序访问策略”才能将 onlineMeetings 创建为应用程序 ( Allow applications to access online meetings on behalf of a user )

所以我的问题是:真的没有直接的方法来创建在线 session 吗?在我看来,这是人们在 Teams 上下文中使用 Microsoft Graph 时想要做的最基本的事情。我不敢相信管理员必须付出如此多的努力,将自己与“Skype for Business Online”- PowerShell ( Configure application access policy ) 连接起来,并手动为每个用户授予权限。我认为 Azure API 权限应该完全涵盖类似的情况。

出于测试目的,我尝试了以下操作,但只得到了 Microsoft.Graph.ServiceException“代码:一般消息:找不到用户。”。我认为这是因为我的 AuthenticationProvider 是 ClientCredentialProvider 并且我正在为用户访问 API。

var client = new GraphServiceClient(azureService.ClientCredentialProvider);
var onlineMeeting = new OnlineMeeting()
{
StartDateTime = start,
EndDateTime = end,
Subject = subject
};

var test = await client.Me.OnlineMeetings
.Request()
.AddAsync(onlineMeeting);

因此,我也尝试了这种方式(Microsoft.Graph.ServiceException: 'Code: BadRequest消息:发生错误。):

var meeting = await client.Communications.OnlineMeetings                    
.Request()
.AddAsync(onlineMeeting);

这样(Microsoft.Graph.ServiceException:'代码:BadRequest消息:不支持此 API。仅/me/onlineMeetings/createorGet 支持 createOrGet 操作:

var meeting = await client.Communications.OnlineMeetings
.CreateOrGet(new Guid().ToString(), null, end, participants, start, subject)
.PostAsync();

那么还有其他 API 或可能性可以满足我的要求吗?与此同时,我有点沮丧,如果有任何提示,我将非常感激。

最佳答案

正如文档所说,添加该策略是必要的,因为应用程序权限不够安全,因为权限非常“大”,而用户权限被微软认为是安全的。

首先,根据我的测试,我发现我可以通过具有正确角色的访问 token 直接创建在线 session (应用程序 OnlineMeetings.ReadWrite.All*),但我更喜欢使用 createEvent相反,因为 this API对于创建在线 session 有更清晰的描述(需要Calendars.ReadWrite的申请权限)。

但是我们还需要注意,即使该操作是由应用程序操作的,但我们仍然需要在请求中设置用户,因为我们需要为 session 设置组织者,我在这里设置我的用户id。我在这里没有运行任何 Power shell 脚本。

enter image description here enter image description here enter image description here

==============这里有一些示例代码===========

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Identity.Client;

namespace ConsoleApp1
{
class Program
{
static async Task Main(string[] args)
{
IConfidentialClientApplication app;
app = ConfidentialClientApplicationBuilder.Create("client_id_here")
.WithClientSecret("client_secret_here")
.WithAuthority(new Uri("https://login.microsoftonline.com/your_tenant_name_here"))
.Build();

AuthenticationResult result = null;
string[] scopes = new string[] { "https://graph.microsoft.com/.default" };
result = await app.AcquireTokenForClient(scopes)
.ExecuteAsync();
string accesstoken = result.AccessToken;
Console.WriteLine(accesstoken);
Console.ReadLine();
//=======
//send http post request here
}
}
}

关于c# - 如何使用 Microsoft Graph 创建 Microsoft Teams session 作为应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68112151/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com