【问题标题】:Authorization_RequestDenied: Insufficient privileges to complete the operation." error with app, only on thirdparty ADAuthorization_RequestDenied:权限不足,无法完成操作。”应用错误,仅在第三方 AD 上
【发布时间】:2018-01-09 04:31:25
【问题描述】:

我正在尝试通过应用程序访问流在我自己和第三方 Azure Active Directory 中搜索用户。 我使用以下内容获取有效令牌。

string authority = string.Format(CultureInfo.InvariantCulture, "https://login.microsoftonline.com/{0}", "<AD>.onmicrosoft.com");
AuthenticationContext authContext = new AuthenticationContext(authority);
ClientCredential clientCredential = new ClientCredential(<clientId>, <appKey>);

AuthenticationResult result = await authContext.AcquireTokenAsync("https://graph.windows.net" , clientCredential);
string TokenForApplication = result.AccessToken;

我使用此方法搜索具有给定名称的用户。

public async Task<List<IUser>> UsersSearch(IActiveDirectoryClient client, string searchString)
{
    List<IUser> usersList = null;
    IPagedCollection<IUser> searchResults = null;

    IUserCollection userCollection = client.Users;
    searchResults = await userCollection.Where(user =>
        user.UserPrincipalName.StartsWith(searchString) ||
        user.GivenName.StartsWith(searchString)).Take(10).ExecuteAsync();
    usersList = searchResults.CurrentPage.ToList();

    return usersList;
}

这一切都在我第一次设置应用程序的 Azure AD 上运行良好。

但是当我尝试在另一个 Azure 活动目录中使用该应用时,我收到错误:Authorization_RequestDenied: Insufficient privileges to complete the operation."

在我原来的 Azure AD 中,我设置了应用程序访问图形 API 和搜索用户所需的所有权限:

在第三方 Azure AD 中,我已经完成了管理流程并授予应用程序所有需要的权限:

据我所知,我获得了每个 Azure AD 的有效令牌,但每当我尝试访问第三方 Azure AD 时,都会收到相同的错误。

我更改要访问的 AD 的方法是更改​​ &lt;AD&gt; in

string authority = string.Format(CultureInfo.InvariantCulture, "https://login.microsoftonline.com/{0}", "<AD>.onmicrosoft.com");

我保持其他一切不变。

【问题讨论】:

    标签: validation oauth-2.0 azure-active-directory microsoft-graph-api adal


    【解决方案1】:

    从您的屏幕截图中,所选权限适用于 Microsoft Graph API(https://graph.microsoft.com),但根据您的代码,您正在获取 Azure AD Graph api(https://graph.windows.net) 的令牌。

    如果你想使用 Azure AD Graph api,你应该在你的多租户应用的 Required permissions 刀片中添加 Windows Azure Active Directory 的权限,并在其他 AAD 中进行管理员同意。

    如果你想使用 Microsoft Graph API,你应该修改你的代码,使用https://graph.microsoft.com而不是https://graph.windows.net

    【讨论】:

    • 谢谢,我没有意识到我实际上在使用 Azure AD Graph API!如果我更改端点,我会得到“BadRequest”:“无效版本”,我收集到这意味着我需要更改我的代码以使用不同的调用集?
    • 您想使用 Azure AD Graph API 或 microsoft graph api 吗?您的 sdk 似乎使用 azure ad graph api。
    • 是的,我从您的回答中了解到,我目前正在使用 Azure AD 图形 API。我想使用 Microsoft 图形 API。
    • 好的,那么你需要制作microsoft graph api list users operation。并且microsoft graph提供.net sdk,你可以查看here的代码示例,尤其是this one
    猜你喜欢
    • 1970-01-01
    • 2019-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多