And*_*ngs 3 c# azure microsoft-teams microsoft-graph-teams microsoft-graph-api
我正在开发一个日历 Web 应用程序,我想在其中创建 Teams 会议并将会议(加入 URL)添加到约会。
由于并非所有用户都通过 Microsoft OAuth 2.0 登录进行登录,因此我必须在服务器端(作为应用程序)创建团队会议。我为我的应用程序创建了一个 Azure 应用程序注册,并为其分配了 API 权限“OnlineMeetings.ReadWrite.All”(应用程序)。我的应用程序正在使用客户端凭据身份验证流程。
现在实际问题是:
我尝试根据此 Microsoft 文档创建 onlineMeeting: Create onlineMeeting
文档说,我必须创建一个“应用程序访问策略”来创建 onlineMeetings 作为应用程序(允许应用程序代表用户访问在线会议)
所以我的问题是:真的没有直接的方法来创建在线会议吗?在我看来,这是人们在 Teams 上下文中使用 Microsoft Graph 时想要做的最基本的事情。我不敢相信管理员必须付出如此多的努力并将自己与“Skype for Business Online”连接 - PowerShell(配置应用程序访问策略)并手动为每个用户授予权限。我认为 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);
Run Code Online (Sandbox Code Playgroud)
因此,我也尝试了这种方式(Microsoft.Graph.ServiceException: 'Code: BadRequest Message: 发生错误。):
var meeting = await client.Communications.OnlineMeetings
.Request()
.AddAsync(onlineMeeting);
Run Code Online (Sandbox Code Playgroud)
这样(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();
Run Code Online (Sandbox Code Playgroud)
那么有没有其他 API 或可能性可以满足我的要求?与此同时,我有点沮丧,非常感谢任何提示。
正如文档所说,添加该策略是必要的,因为应用程序权限不够安全,因为权限非常“大”,而用户权限被微软认为是安全的。
首先,根据我的测试,我发现我可以通过具有正确角色的访问令牌直接创建在线会议(应用程序 OnlineMeetings.ReadWrite.All*),但我更喜欢使用createEvent,因为这个 API具有更清晰的功能创建在线会议的说明(需要申请Calendars.ReadWrite权限)。
但我们还需要注意的是,即使该操作是由应用程序操作的,但我们仍然需要在请求中设置一个用户,因为我们需要为会议设置一个组织者,我在这里设置我的用户id。我这里没有运行任何 power shell 脚本。
===============这里有一些示例代码===========
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
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3858 次 |
| 最近记录: |