Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure AD通过Azure CLI添加密钥_Azure_Azure Active Directory_Azure Ad Graph Api_Azure Cli - Fatal编程技术网

Azure AD通过Azure CLI添加密钥

Azure AD通过Azure CLI添加密钥,azure,azure-active-directory,azure-ad-graph-api,azure-cli,Azure,Azure Active Directory,Azure Ad Graph Api,Azure Cli,我正在尝试使用Azure CLI在Azure AD应用程序中添加密钥。 但纵观Azure CLI API,似乎没有这样的命令 对于exmaple: 我正在尝试通过Azure CLI从以下链接自动执行任务: 我可以创建广告应用程序,服务主体,但我找不到为新创建的广告应用程序添加密钥的方法 我将感谢您的任何想法和指导:) 提前谢谢 我没有任何自动添加密钥的经验,老实说,我不确定这是否可行。但是,请查看Graph API中的文档,可以使用对web服务的POST请求。对于新的AD应用程序,您可以在创建

我正在尝试使用Azure CLI在Azure AD应用程序中添加密钥。 但纵观Azure CLI API,似乎没有这样的命令

对于exmaple:

我正在尝试通过Azure CLI从以下链接自动执行任务:

我可以创建广告应用程序,服务主体,但我找不到为新创建的广告应用程序添加密钥的方法

我将感谢您的任何想法和指导:)


提前谢谢

我没有任何自动添加密钥的经验,老实说,我不确定这是否可行。但是,请查看Graph API中的文档,可以使用对web服务的POST请求。

对于新的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>
azure广告应用程序创建-n-主页-i-p
对于现有的AD应用程序,Graph API肯定能够更新AD应用程序凭据。阅读,您可以看到密码凭证能够使用“POST、GET、PATCH”。但是,使用Graph API太复杂了。我已经检查了Azure CLI。该功能尚未实现,而且源代码对我来说不可读。然后,我看了一下Azure SDK for Python,因为我熟悉Python,我发现他们已经在2.0.0rc2中实现了它。见

我已经写了一个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)
从azure.common.credentials导入UserPassCredentials
从azure.graphrbac导入GraphRbacManagementClient,GraphRbacManagementClientConfiguration
从azure.graphrbac.models导入ApplicationCreateParameters、PasswordCredential
凭据=UserPassCredentials(“,”)
订阅\u id=“”
租户_id=“”
graphrbac_客户端=graphrbac管理客户端(
GraphRbacManagementClientConfiguration(
资格证书
订阅id,
租户身份证
)
)
application=graphrbac_client.application.get(“”)
passwordCredential=passwordCredential(start_date=“2016-04-13T06:08:04.0863895Z”,
end_date=“2018-04-13T06:08:04.0863895Z”,
值=”)
参数=ApplicationCreateParameters(application.available\u可供其他租户使用,
application.display\u名称,
"",
application.identifier\u URI,
reply\u url=application.reply\u url,
密码\凭证=[passwordCredential])
application=graphrbac_client.application.update(“”,参数)

此脚本的唯一问题是,您只能覆盖AD应用程序的所有现有密钥。您无法附加新密钥。这是Graph API的一个问题。Graph API不允许用户读取现有密钥。一种可能的解决方案是将现有密钥存储在其他地方。但是,这将带来额外的安全风险。

添加密钥是什么意思?2017年底,仍然无法通过CLI实现这一点