【问题标题】:Can't retreive displayName for an Azure AD tenant无法检索 Azure AD 租户的显示名称
【发布时间】:2017-08-06 15:37:58
【问题描述】:

问题

无法检索租户的 displayName

没关系

我的应用程序是一个多租户网站。 我使用 Open Id Connect 对客户进行身份验证,并从代码授权流程中获取访问令牌(例如 armToken)以运行此请求:

https://management.azure.com/tenants

获取声明客户的所有租户的列表。说是租户。

这很好用。

哪里出错了

然后我想获取有关所有租户的更多信息,因为它是显示名称。 所以我需要为 Tenants 上的每个租户运行此请求:

https://graph.windows.net/[tenantId]/tenantDetails?api-version=1.6

我使用这样的代码:

foreach (Tenant tenant in Tenants)
{
   string graphToken = await 
   GetAuthorizationToken("https://graph.windows.net/", tenant.TenantId);
   string json = await GetGraphRequest($"https://graph.windows.net/{tenant.TenantId}/tenantDetails? api-version=1.6", graphToken);

// I parse JSON to get my informations
}

我尝试了什么

问题可能出在 GetAuthorizationToken 方法中,该方法未检索到正确的令牌。 我测试了所有 AcquireTokenAsync 签名,除了:

AcquireTokenAsync(string resource, ClientCredential clientCredential);

但收到的令牌仅在租户测试与用户声明中找到的 TID 匹配的情况下有效。

根据租户的不同,我会收到几条消息:

{"odata.error":{"code":"Authorization_RequestDenied","message":{"lang":"en","value":"权限不足,无法完成操作。"}} }

==> 但我在 Microsoft Grant

上授予了所有可能的权限

或

{"odata.error":{"code":"Authorization_IdentityNotFound","message":{"lang":"en","value":"无法建立调用应用程序的身份."}}}

=> 实际上,我在令牌中没有声明为 OID

  • 我检查了 uri 中没有斜杠问题。
  • 我检查了 Postman 的 Graph 请求,以确保这不是代码中的问题
  • 我是全球管理员

我的问题

我真的不知道我还能做什么。

这应该是可能的,因为我可以看到它在这里工作:

https://github.com/projectkudu/AzureResourceExplorer/

但它不使用 ADAL 库。那么也许这个库有限制?

【问题讨论】:

    标签: c# azure-active-directory adal azure-ad-graph-api


    【解决方案1】:

    如果用户使用 azure ad 帐户登录您的应用程序,使用 azure ad graph apitenantDetails 操作,您只能获取颁发访问令牌的租户详细信息。否则会报错:Invalid domain name in the request url.

    要获取与用户帐户关联的所有 Azure AD 实例的列表,您可以尝试 Windows Azure 服务管理 API,请参阅my reply here。作为响应,您可以获得租户的 displayName、domainName、ID。

    【讨论】:

    • 我刚刚得到"AADSTS70002:请求正文必须包含以下参数:'client_secret or client_"。 Seams 不支持代码授予。这很令人惊讶,因为它在门户网站上运行良好。
    • 如果您在azure portal中注册了web应用,您需要在code grant时提供client secret,详情请点击here。
    • 有什么更新吗?如果您有任何问题,请随时告诉我。
    • 我病了几天了,自从你上次发帖后就没有检查了,对不起!
    • 希望你早日康复:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-30
    • 2021-09-19
    • 2019-11-19
    • 1970-01-01
    • 2020-02-28
    • 2019-01-08
    相关资源
    最近更新 更多