For a new AD application, you can specify the -p switch when creating. For example,
azure ad app create -n <your application name>
For an existing AD application, of course, the Graph API can update the credentials of the AD Application. Read this API link and you will see that password credentials can use "POST, GET, PATCH". However, it is too difficult to use the Graph API. I checked the Azure CLI. This functionality has not yet been implemented, and the source is not readable to me. Then I looked at the Azure SDK for Python, because I am familiar with python, and I found out that they already implemented it in 2.0.0rc2. See GitHub Repo
I wrote a python script. But to use my script you need to install not only azure2.0.0rc2, but also msrest and 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)
The only problem with this script is that you can only override all existing keys of your AD application. You cannot add a new key. This is a problem of the Graph API. The Graph API does not allow users to read an existing key. One possible solution would be to store your existing keys in a different place. But this will bring an additional security risk.
Jack zeng
source share