How to generate client secret in azure app registration in Azure AD from CLI?

19.5k Views Asked by At

How can I use AZ commands to create client secret the same way I can do it from the portal? Creating client secret from portal

2

There are 2 best solutions below

4
Joy Wang On

You are looking for az ad app credential reset, it appends or overwrites an application's password(i.e. client secret) or certificate credentials.

az ad app credential reset --id
                           [--append]
                           [--cert]
                           [--create-cert]
                           [--credential-description]
                           [--end-date]
                           [--keyvault]
                           [--password]
                           [--years]

Sample(you can also specify other parameters, it depends on you):

az ad app credential reset --id xxxxxxxxxxxx --append

enter image description here

0
Jhonny Ramirez Zeballos On

Get ID Client of app register for example: "appId": "b23e2416-xxxx-xxxx-98d4"

Create:

az ad app credential reset --id b23e2416-xxxx-xxxx-98d4 --append \
  --display-name 'Description: Secret Bolivian client' --end-date '2024-12-31'

Output:

The output includes credentials that you must protect. 
Be sure that you do not include these credentials in your code or check the credentials into your source control. 
For more information, see https://aka.ms/azadsp-cli
{
   "appId": "b23e2416-xxxx-xxxx-98d4",
   "password": "rp28Q~VNlFt-xxxxxxxxxxxxxxxxxxxxxxx",
   "tenant": "67f3b853-xxxx-xxxx-xxxx"
}