【问题标题】:getMemberGroups “Insufficient privileges to complete the operation”getMemberGroups “权限不足,无法完成操作”
【发布时间】:2017-06-13 16:59:52
【问题描述】:

我编写了一个应该读取用户组的应用程序。我正在使用 Asp.net 核心。我在 azure 门户中创建了一个应用程序,并授予了 GraphAPI 的 all 应用程序权限,然后单击了授予权限按钮。然后我使用了一些类似于WebApp-GroupClaims-DotNet 的代码来检索用户组:

public async Task<IEnumerable<string>> GetGroupIdsFromGraphApiAsync(string userId)
{
    var groupObjectIds = new List<string>();

    // Acquire the Access Token
    var credential = new ClientCredential(_configHelper.ClientId, _configHelper.AppKey);
    var authContext = new AuthenticationContext(_configHelper.Authority);
    var result = await authContext.AcquireTokenAsync(_configHelper.GraphResourceId, credential);
    var accessToken = result.AccessToken;

    var requestUrl =
        $"{_configHelper.GraphResourceId}/{_configHelper.Domain}/users/{userId}/getMemberGroups?api-version=1.6";

    // Prepare and Make the POST request
    var client = new HttpClient();
    var request = new HttpRequestMessage(HttpMethod.Post, requestUrl);
    request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
    var content = new StringContent("{\"securityEnabledOnly\":false}");
    content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
    request.Content = content;
    var response = await client.SendAsync(request);

    // Endpoint returns JSON with an array of Group ObjectIDs
    if (response.IsSuccessStatusCode)
    {
        var responseContent = await response.Content.ReadAsStringAsync();
        var groupsResult = (Json.Decode(responseContent)).value;

        foreach (string groupObjectId in groupsResult)
            groupObjectIds.Add(groupObjectId);
    }
    else
    {
        var responseContent = await response.Content.ReadAsStringAsync();
        throw new WebException(responseContent);
    }

    return groupObjectIds;
}

不幸的是,我总是得到以下回复:

{"odata.error":{"code":"Authorization_RequestDenied","message":{"lang":"en","value":"Insufficient privileges to complete the operation."}}}

应用程序是否无法向 AD 查询此信息?

【问题讨论】:

  • _configHelper.GraphResourceId 的值是多少。似乎您正在使用 azure ad graph api,您是否在 azure 门户中授予 Windows Azure Active Directory(azure ad graph api) 的权限?
  • _configHelper.GraphResourceIdhttps://graph.windows.net
  • 那么在 azure 门户中,您授予哪一个权限? Azure Active Directory 或 Microsoft Graph?以及哪个应用程序权限?
  • 我添加了 Microsoft Graph 应用程序权限,但现在添加 Azure Active Directory 权限后它就可以工作了……这是为什么呢?我认为使用 graph.windows.net 会映射到 Microsoft Graph,而不是 AAD ...
  • 请看我的回答。

标签: asp.net azure azure-active-directory microsoft-graph-api


【解决方案1】:

根据您的代码,您正在进行 Azure 广告图 api 调用,那么您需要授予 Windows Azure Active Directory(azure ad 图 api)的权限。

https://graph.windows.net 是 Azure AD Graph APi 的端点,在 azure 门户中名称为 Windows Azure Active Directoryhttps://graph.microsoft.com 是 Microsoft Graph api 的端点,在 Azure 门户中名称为 Microsoft Graph

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-03
    • 2018-06-13
    • 2018-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多