Đối với ứng dụng AD mới, bạn có thể chỉ định khóa bằng -p
khi tạo. Ví dụ:
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>
Đối với ứng dụng AD hiện tại, chắc chắn Graph API có thể cập nhật Thông tin đăng ký AD. Đọc this API reference và bạn có thể thấy rằng thông tin xác thực mật khẩu có thể sử dụng "POST, GET, PATCH". Tuy nhiên, quá phức tạp để sử dụng API đồ thị. Tôi đã kiểm tra Azure CLI. Chức năng đó chưa được triển khai và nguồn không thể đọc được đối với tôi. Sau đó, tôi đã xem xét Azure SDK cho Python, bởi vì tôi quen thuộc với python, và tôi phát hiện ra rằng họ đã thực hiện nó trong 2.0.0rc2. Xem GitHub Repo
Tôi đã viết một tập lệnh python. Nhưng, để sử dụng kịch bản của tôi, bạn cần cài đặt không chỉ azure2.0.0rc2, mà còn cả msrest và 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)
Vấn đề duy nhất với tập lệnh này là bạn chỉ có thể ghi đè tất cả các khóa hiện có của ứng dụng AD. Bạn không thể nối thêm khóa mới. Đây là một vấn đề của Graph API. Graph API không cho phép người dùng đọc một khóa hiện có. Một giải pháp có thể sẽ được lưu trữ các khóa hiện tại của bạn ở một nơi khác. Tuy nhiên, điều này sẽ mang lại thêm rủi ro bảo mật.
Nguồn
2016-04-13 07:39:07
điều gì khiến bạn muốn nói bằng cách thêm khóa? – Thomas
vào cuối năm 2017 và vẫn không thể thực hiện điều đó thông qua CLI – MMT