【问题标题】:How Do I Query Azure Active Directory For An Application Client Secret?如何在 Azure Active Directory 中查询应用程序客户端密码?
【发布时间】:2019-12-27 04:15:24
【问题描述】:

我需要将我的 API 管理与 Azure Active Directory 身份提供程序相关联。

为了做到这一点,我必须使用需要客户端密码作为正文一部分的 REST API:

https://docs.microsoft.com/en-us/rest/api/apimanagement/2019-01-01/identityprovider/createorupdate

我不想将客户端密码签入源代码控制,所以我想我会即时从 Active Directory 中检索客户端密码:

当我尝试 list the app credentialsaz ad app credential list --id xxxx-my-long-id-xxx 时,它不会返回秘密:

[
  {
    "additionalProperties": null,
    "customKeyIdentifier": null,
    "endDate": "2020-08-16T14:11:44.782000+00:00",
    "keyId": "xxxxx-xxxx-x-xxx--xx-xxxxx",
    "startDate": "2019-08-16T14:11:53.862000+00:00",
    "value": null
  }
]

是否有其他方法可以获取客户端密码?

也许通过其余的 api?

【问题讨论】:

    标签: azure azure-active-directory


    【解决方案1】:

    对于服务主体秘密,您可以在创建时查看它。在创建时间之后,您将永远不会看到它。因此,如果您忘记了服务主体密码,您只需重置该密码,然后您就可以获得一个新密码。可以看到here的消息:

    确保复制此值 - 无法检索。如果你忘记了 密码,重置服务主体凭据。

    这里的重置命令:

    az ad sp credential reset --name yourApplicationName
    

    有关该命令的更多详细信息,请参阅az ad sp credential reset

    【讨论】:

    • 嗯,但是az ad sp credential list 会告诉你秘密,对吧?所以一定有办法解决它....
    • @HongOoi 不行,创建后就无法获取了。
    • @HongOoi 我刚刚用下面的代码验证了,没有密码:az ad app create --display-name ServicePrincipalDemo1 --homepage "http://localhost/ServicePrincipalDemo1" az ad sp create-for-rbac --name ServicePrincipalDemo1 az ad sp credential list --id 7e4ac22c-3b86-48fb-9805-0ffc07c2c0dd
    【解决方案2】:

    创建后看不到它,但是可以将其保存到 Azure Key Vault 并在每次需要发出请求时从那里提取值。

    【讨论】:

    • 这听起来很有潜力。你能添加一些关于如何做到这一点的代码吗?上面的命令是缺少 terraform 功能的解决方法,所以如果你能举一个 terraform 的例子会更好。
    猜你喜欢
    • 2017-07-29
    • 1970-01-01
    • 2020-02-15
    • 2020-03-09
    • 1970-01-01
    • 2016-03-28
    • 1970-01-01
    • 2014-12-27
    • 2019-04-28
    相关资源
    最近更新 更多