对于新的 AD 应用程序,您可以指定一个密钥-p
创作时。例如,
azure ad app create -n <your application name> --home-page <the homepage of you application> -i <the identifier URI of you application> -p <your key>
对于现有的 AD 应用程序,Graph API 当然能够更新 AD 应用程序凭据。读这个API参考,可以看到密码凭证可以使用“POST、GET、PATCH”。然而,使用 Graph API 太复杂了。我已经检查了 Azure CLI。该功能尚未实现,并且源代码对我来说无法读取。然后,我看了一下Azure SDK for Python,因为我对python很熟悉,我发现他们已经在2.0.0rc2中实现了它。请参阅GitHub 存储库
我写了一个Python脚本。但是,为了使用我的脚本,您不仅需要安装 azure2.0.0rc2,还需要安装 msrest 和 msrestazure。
from azure.common.credentials import UserPassCredentials
from azure.graphrbac import GraphRbacManagementClient, GraphRbacManagementClientConfiguration
from azure.graphrbac.models import ApplicationCreateParameters, PasswordCredential
credentials = UserPassCredentials("<your Azure Account>", "<your password>")
subscription_id = "<your subscription id>"
tenant_id = "<your tenant id>"
graphrbac_client = GraphRbacManagementClient(
GraphRbacManagementClientConfiguration(
credentials,
subscription_id,
tenant_id
)
)
application = graphrbac_client.application.get('<your application object id>')
passwordCredential = PasswordCredential(start_date="2016-04-13T06:08:04.0863895Z",
end_date="2018-04-13T06:08:04.0863895Z",
value="<your new key>")
parameters = ApplicationCreateParameters(application.available_to_other_tenants,
application.display_name,
"<the homepage of your AD application>",
application.identifier_uris,
reply_urls=application.reply_urls,
password_credentials = [passwordCredential])
application = graphrbac_client.application.update('<your application object id>', parameters)
该脚本的唯一问题是您只能覆盖 AD 应用程序的所有现有密钥。您无法附加新密钥。这是 Graph API 的问题。 Graph API 不允许用户读取现有密钥。一种可能的解决方案是将现有密钥存储在其他地方。但是,这会带来额外的安全风险。