【问题标题】:Unable to fetch using RoleManagement API endpoints in azure graph-api无法在 azure graph-api 中使用 RoleManagement API 端点获取
【发布时间】:2019-11-06 18:33:17
【问题描述】:

我正在尝试使用 azure Graph API 来获取具有特定角色的用户。下面的代码 sn-p 作为我生成 authToken 的方式

AuthenticationContext authenticationContext = new AuthenticationContext(_authString, false);
            ClientCredential clientCred = new ClientCredential(_clientId, _clientSecret);
            AuthenticationResult authenticationResult;
            if (_authenticationResult == null || true == CanAcquireToken)
            {
                authenticationResult = authenticationContext.AcquireTokenAsync(_resAzureGraphAPI, clientCred).GetAwaiter().GetResult();
                _authenticationResult = authenticationResult;
            }
            return _authenticationResult.AccessToken;

Graph API 对我的应用程序的权限列表快照: GraphAPI permissions on application

我阅读了https://docs.microsoft.com/en-us/graph/api/rbacapplication-list-roleassignments?view=graph-rest-beta&tabs=http 以了解 API 端点以及相应 appRegistration 上 Graph API 所需的一组权限。

我已为正在审核的应用程序提供了所需权限集的图形 API。 但是,API 请求

https://graph.microsoft.com/{{beta}}/roleManagement/directory/roleAssignments?$filter=roleDefinitionId eq '{{roleDefnId-Guid}}'

总是失败并显示错误详细信息

访问令牌验证失败。无效的观众

注意:生成的身份验证令牌已成功从“https://docs.microsoft.com/en-us/graph/api/approleassignment-get?view=graph-rest-beta&tabs=http”提到的调用中获取我的信息

【问题讨论】:

  • 你是如何生成令牌的?您能否更新问题中的步骤?
  • 嗨,Joy,已使用 authToken 生成代码 sn-p 和我在应用程序上为 GraphAPI 提供的权限列表编辑了我的帖子
  • 顺便说一句,https://graph.microsoft.com/{{beta}}/ 应该是https://graph.microsoft.com/beta/,你用对了吗?
  • 我所指的整个 URL 是“graph.microsoft.com/beta/roleManagement/directory/… eq 'Guid'” 我怀疑它如何检查我所指的正确应用程序
  • 检查我的答案,有什么更新吗?

标签: azure-active-directory microsoft-graph-api


【解决方案1】:

你的应用权限正确,Directory.ReadWrite.All应用权限就够了。我也测试了你的代码,它工作正常。

确保你代码中的_resAzureGraphAPIhttps://graph.microsoft.com(再确认一下,我知道如果错了,你将无法调用Note中的api)。我可以用错误的问题重现您的问题,例如https://graph.windows.net.

如果_resAzureGraphAPI是正确的,在https://jwt.io/中解码你的token,看和下图一样。

【讨论】:

    猜你喜欢
    • 2016-02-15
    • 1970-01-01
    • 1970-01-01
    • 2018-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多