繁体   English   中英

从 Azure Active Directory 访问权限类型为已委派的用户

[英]Access users from Azure active Directory having persmison type as delegated

我是 Azure 的新手。 我有一个要求从 Azure 活动目录中检索用户。 我有委托类型,以及 user.Read 和 users.Readall。

我能够获得不记名代码,但是当它检索用户时,我的权限被拒绝。 我需要用 C# 编写一个控制台应用程序,下面是我尝试过的代码。

var app = ConfidentialClientApplicationBuilder.Create(clientID)
               .WithClientSecret(Secret)
               .WithRedirectUri(URL)
               .WithAuthority("https://login.microsoftonline.com/tenantID/oauth2/token")
               .Build();

            string[] scopes = new string[] { "https://graph.microsoft.com/.default" };
            var token = app.AcquireTokenForClient(scopes).ExecuteAsync().Result;

 - GraphServiceClient graphClient1 = new
   GraphServiceClient("https://graph.microsoft.com/v1.0", new
   DelegateAuthenticationProvider(async (requestMessage) =>
               {
                   requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", token.AccessToken);
               }));
   
               var users = graphClient1.Users.Request().Top(99).GetAsync();
               var organization = graphClient1.Organization.Request().GetAsync().Result;

我在下面

system.AggregateException: 'One or more errors occurred. (Code: Authorization_RequestDenied
Message: Insufficient privileges to complete the operation.
for the LIne **var organization = graphClient1.Organization.Request().GetAsync().Result;**
Need help on this

提前致谢。

由于您使用委派权限它要求用户登录到使用这些permisssions.So, https://graph.microsoft.com/.default是不正确的范围,应与授权许可,例如https://graph.microsoft.com/User.Read.All

此外,您需要在图形请求之前使用 await,

var users = await graphClient.Users.Request().Top(99).GetAsync();

由于您是 Ms Graph 的新手,请查看一个简单的控制台应用程序代码示例,以帮助您轻松实现。

暂无
暂无

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

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