使用 microsoft graph api c# 创建在线会议时出现 404 错误,但未登录 AzureActiveDirectory
Posted
技术标签:
【中文标题】使用 microsoft graph api c# 创建在线会议时出现 404 错误,但未登录 AzureActiveDirectory【英文标题】:404 error while creating Online Meeting using microsoft graph api c# without login into AzureActiveDirectory 【发布时间】:2021-01-10 14:00:27 【问题描述】:我正在尝试使用 microsoft graph api 创建在线会议,而无需使用 asp.net Web 应用程序登录到 AzureActiveDirectory。为此,我的应用程序具有以下权限,这是根据文档https://docs.microsoft.com/en-us/graph/api/application-post-onlinemeetings?view=graph-rest-1.0&tabs=csharp 和客户端凭据身份验证流https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-client-creds-grant-flow 所需的权限立即与用户交互。我能够根据客户端信用授权流成功检索访问令牌。 我尝试了 Micosoft.Graph 和 Micosoft.Graph.Beta 仍然出现 404 错误。
创建在线会议代码
var graphClient = GetAuthenticatedClientCredential();
var onlineMeeting = new OnlineMeeting
StartDateTime = DateTimeOffset.Parse("2020-10-01T10:30:34.2444915+00:00"),
EndDateTime = DateTimeOffset.Parse("2020-10-01T11:00:34.2464912+00:00"),
Subject = "Create Online Meeting-Without user login to Office 365"
;
return await graphClient.Me.OnlineMeetings
.Request()
.AddAsync(onlineMeeting);
访问令牌代码
public static async Task<string> GetUserAccessTokenAsyncByCc()
IConfidentialClientApplication cca = ConfidentialClientApplicationBuilder.Create(appId)
.WithTenantId(appTenantId)
.WithClientSecret(appSecret)
.Build();
string[] scopes1 = new string[] "https://graph.microsoft.com/.default" ;
//string[] scopes1 = new string[] "https://graph.microsoft.com/OnlineMeetings.ReadWrite.All" ;
// string[] scopes1 = new string[] "https://graph.microsoft.com/beta/OnlineMeetings.Read.All" ;
//string[] scopes1 = new string[] "https://graph.microsoft.com/beta/.default" ;
var result = await cca.AcquireTokenForClient(scopes1).ExecuteAsync();
return result.AccessToken;
和身份验证提供程序代码
public static GraphServiceClient GetAuthenticatedClientCredential()
DelegateAuthenticationProvider provider = new DelegateAuthenticationProvider(
async (requestMessage) =>
string accessToken = await GetUserAccessTokenAsyncByCc();
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
);
GraphServiceClient graphClient = new GraphServiceClient(provider);
return graphClient;
应用权限图片 below are the necessary app permission
【问题讨论】:
【参考方案1】:您只能使用委派权限创建onlineMeeting,因此您必须以用户身份登录,并且不能使用客户端凭据流。需要使用auth code flow获取token。
【讨论】:
我已经使用auth code flow来获取token并通过登录到login.microsoftonline.com/common/>[returns auth code in redirecturl]成功创建了onlinemetting。但要求是没有登录到 login.microsoftonline.com/common> 用户应该通过登录到我们的 webapp 来汇总详细信息来创建在线会议。 @anu 我不太明白你的意思。 好的,让我解释一下。身份验证代码提供程序需要redirectURL 来返回身份验证码,但在该用户必须登录之前,用户必须登录以上是关于使用 microsoft graph api c# 创建在线会议时出现 404 错误,但未登录 AzureActiveDirectory的主要内容,如果未能解决你的问题,请参考以下文章
MS Graph API:microsoft.graph.createLink 未创建匿名视图链接
使用 microsoft graph api 检出 onedrive 文件的状态
如何使用 microsoft graph api 获取 EndRecurrenceDate
获取 Microsoft Graph API 的有效访问令牌