【问题标题】:AzureAD multiteenant app - "Authorization_RequestDenied": "Insufficient privileges to complete the operationAzureAD 多青少年应用程序 - “Authorization_RequestDenied”:“权限不足,无法完成操作
【发布时间】:2017-03-31 12:31:41
【问题描述】:

我指的是Multitenant-saas-app 示例。我正在尝试获取访问令牌以访问 Graph API,然后静默获取访问令牌并再次访问图形 API。

使用多租户应用的 /common 端点获取授权码,

private string resourceID = "https://graph.windows.net";

 string authorizationRequest = String.Format(
                "https://login.microsoftonline.com/common/oauth2/authorize?response_type=code&client_id={0}&resource={1}&redirect_uri={2}&state={3}",
                 Uri.EscapeDataString(ConfigurationManager.AppSettings["ida:ClientID"]),
                 Uri.EscapeDataString("https://graph.windows.net"),
                 Uri.EscapeDataString(this.Request.Url.GetLeftPart(UriPartial.Authority).ToString() + "/Onboarding/ProcessCode"),
                 Uri.EscapeDataString(stateMarker)
                 );
return new RedirectResult(authorizationRequest);

使用授权码重定向,(/Onboarding/ProcessCode)

  ClientCredential credential = new ClientCredential(ConfigurationManager.AppSettings["ida:ClientID"],
                                                                   ConfigurationManager.AppSettings["ida:Password"]);
                AuthenticationContext authContext = new AuthenticationContext("https://login.windows.net/common/");

                //Get token to access grapgh API
                AuthenticationResult result = await authContext.AcquireTokenByAuthorizationCodeAsync(
                   code, new Uri(Request.Url.GetLeftPart(UriPartial.Path)), credential, resourceID);

                AuthenticationHelper.token = result.AccessToken;

这很好,我获得了访问令牌,我可以在其中访问租户的 AzureAD 资源。

 ActiveDirectoryClient client = AuthenticationHelper.GetActiveDirectoryClient();
                IPagedCollection<IUser> pagedCollection = await client.Users.ExecuteAsync();

现在我尝试从令牌缓存中获取令牌以进行离线访问。这次我为租户创建 AuthenticationContext。 (我也试过 /common ) 这会默默地给我一个新的访问令牌。

 string resourceID = "https://graph.windows.net";
            //Test
            ClientCredential credential = new ClientCredential(ConfigurationManager.AppSettings["ida:ClientID"],
                                                                       ConfigurationManager.AppSettings["ida:Password"]);

            AuthenticationContext authContext = new AuthenticationContext("https://login.microsoftonline.com/mytenant.net");

            var auth = await authContext.AcquireTokenAsync(resourceID, credential);

            var newToken = auth.AccessToken;
            //Set the token for this session
            AuthenticationHelper.token = auth.AccessToken;

然后我尝试像以前一样访问 API,

ActiveDirectoryClient client = AuthenticationHelper.GetActiveDirectoryClient();
                IPagedCollection<IUser> pagedCollection = await client.Users.ExecuteAsync();

我得到以下异常,

Error = "Authorization_RequestDenied": "权限不足 完成操作。”

我在这里做错了吗?

这是我的应用权限,

【问题讨论】:

  • 当您使用多租户应用程序时,租户管理员需要授予对应用程序的访问权限。也许这就是问题所在?是否有任何进一步的错误消息详细信息?

标签: c# asp.net-mvc adal azure-ad-graph-api


【解决方案1】:

要使用 Azure AD 图表 REST 列出用户,如果您不是全球用户,我们需要 阅读所有用户的基本个人资料阅读所有用户的完整个人资料租户中的管理员。

如果您是租户中的全局管理员以登录用户身份访问目录也应该可以列出用户rest API。

有关 Azure AD 图表的范围的更多详细信息,您可以参考here

对于缓存问题,由于您没有提供自定义缓存,它将使用基于平台的默认缓存。例如,如果您正在开发一个 .Net 应用程序,缓存正在使用内存来存储对象。所以它只在您重新启动应用程序之前有效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-30
    • 2018-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多