Skip to main content

How to Create a Client Secret for an App Registration in Microsoft Entra ID

· 8 min read
Jagdish Kumawat
Founder @ Dewiride

When an app has to sign in as itself, with no person involved, it needs a credential of its own. The simplest is a client secret: a password that belongs to the app registration. This guide creates one in the Microsoft Entra admin center, shows the one moment you can copy it, and deletes it again.

What a Client Secret Is​

An app registration in Microsoft Entra ID has an Application (client) ID, which says which app it is. To prove it really is that app when it asks for a token, the app also needs a credential. Microsoft's guide to app credentials lists three kinds:

CredentialWhat it isMicrosoft's advice
Client secretA random string, the app's passwordConvenient for local development; should not be used in production
CertificateA public key whose private key only the app holdsRecommended over a secret
Federated credentialTrust in tokens from another identity provider, such as GitHub Actions or a managed identityNo secret to keep at all

This guide is about the first. The example is an app registration for a nightly report job, a program that runs at night and signs in as itself.

Creating a client secret costs nothing.

Prerequisites​

  • An app registration in Microsoft Entra ID that you can change: you're one of its owners, or you have the Application Administrator or Cloud Application Administrator role.

Step 1: Open Certificates & Secrets​

  1. Open the Microsoft Entra admin center and browse to Entra ID > App registrations.
  2. Select your app, then Certificates & secrets under Manage.
  3. Make sure the Client secrets tab is selected, and select New client secret.

The Certificates & secrets page of the Nightly Report Job app registration: the Client secrets (0) tab selected, No client secrets have been created for this application., and the New client secret button highlighted

The page's own description is the shortest definition there is: A secret string that the application uses to prove its identity when requesting a token. Also can be referred to as application password.

Step 2: Describe the Secret and Choose When It Expires​

The Add a client secret pane opens on the right:

  1. Description: what the secret is for, so you can tell it from others later. I used Nightly report job.
  2. Expires: how long the secret works. Open the list to see the choices:

The Add a client secret pane: Description Nightly report job, and the Expires list open with Recommended: 180 days (6 months), 90 days (3 months), 365 days (12 months), 545 days (18 months), 730 days (24 months) and Custom

Microsoft's guide says a client secret can live for 24 months at most, and recommends less than 12. Keep the recommended 180 days (6 months) unless you have a reason not to. A secret that never expires isn't an option.

  1. Select Add at the bottom of the pane:

The Add a client secret pane filled in: Description Nightly report job, Expires Recommended: 180 days (6 months), and the Add button highlighted next to Cancel

Step 3: Copy the Value Now​

The new secret appears in the list:

The Client secrets (1) tab with one row: Nightly report job, expiring 5/23/2027, its Value starting Abc8Q~ with a copy button, highlighted, and a Secret ID with its own copy button and a delete button

Select the copy button next to Value, and paste the value where your app will read it, straight away. The value in these screenshots is replaced with Abc8Q~xxxx…; yours is a real one, and it's the only time you'll see it. The Value column's information icon says so:

The tooltip of the Value column: Client secret values cannot be viewed, except for immediately after creation. Be sure to save the secret when created before leaving the page.

The row has two long strings, and only one of them is the secret:

ColumnWhat it isDo you need it?
ValueThe secret itself, the app's passwordYes: your app sends it when it asks for a token
Secret IDAn ID for the secret entry, so it can be told apart from othersNo: it's not a password, and it won't sign in anything

The expiry date is also in the row: this secret stops working on 5/23/2027, 180 days after it was created.

Step 4: Keep It Out of Your Code​

A client secret is a password, so treat it like one: never in source code, never in appsettings.json, never in a chat or a ticket. Where to put it depends on where the app runs:

If you lose the value, you can't get it back. Create a new secret and delete the old one.

Step 5: Delete a Secret You No Longer Need​

When the app no longer uses a secret, or the value may have been seen by someone it shouldn't have, delete it: select the bin icon at the end of its row. The admin center asks first:

The question Are you sure you want to delete this client secret? with Description: Nightly report job and the Yes button highlighted next to No, above the secret's row

Select Yes. The row disappears, and anything still using that value can no longer get tokens.

Common Mistakes​

MistakeWhat happensDo this instead
Copying the Secret ID instead of the ValueSign-in fails, because the ID isn't the passwordCopy the Value
Leaving the page before copying the valueThe value is hidden for goodCreate a new secret and delete the unused one
Putting the value in appsettings.json or codeAnyone who can read the repository has the app's passwordUse user secrets on your machine and a key vault in Azure
Forgetting the expiry dateThe app stops signing in on that dayNote the date, and replace the secret before it

Troubleshooting​

SymptomLikely causeFix
The Value column no longer shows the whole valueYou left the page and came back, and the value is hidden for goodCreate a new secret
The app can no longer get tokens with its secretThe secret expired or was deleted, or the app was given the Secret IDCheck the row's expiry, and use the Value of a current secret

FAQ​

Can I see a secret's value again later?​

No. Microsoft's guide: This secret value is never displayed again after you leave this page. Create a new one if you need it.

Can an app have more than one secret?​

Yes, the list holds several. That's how you replace one without downtime: add the new secret, move the app to it, then delete the old one.

Should my production app use a client secret?​

Microsoft says no: use a certificate, a federated credential, or a managed identity. A client secret is for development and testing.

Conclusion​

A client secret is an app registration's password. Create it under Certificates & secrets, choose an expiry of a year or less, copy the Value before you leave the page, and keep it out of your code. Delete it as soon as nothing uses it.

Additional Resources​