繁体   English   中英

使用 microsoft graph api c# 创建在线会议时出现 404 错误,而无需登录 AzureActiveDirectory

[英]404 error while creating Online Meeting using microsoft graph api c# without login into AzureActiveDirectory

我正在尝试使用 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无需立即与用户交互。我能够按照 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;


        }

下面的应用权限图片是必要的应用权限

您只能使用委派权限创建onlineMeeting ,因此您必须以用户身份登录,并且不能使用客户端凭据流 您需要使用身份验证代码流来获取令牌。

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM