48h onlyLifetime deal: pay once from $100, keep Keysquid forever. No subscription.Ends in 30:34:36See the deal
Skip to content
Rotate › Microsoft Entra ID

How to rotate an Azure app registration client secret

Every Entra ID client secret has an end date, and when it passes, sign-ins fail with AADSTS7000222. The fix is the same whether you're ahead of the deadline or past it: add a second secret, move your apps to it, check the sign-in logs, then remove the old one. Two details cause most outages: the az CLI command that deletes every other secret unless you add one flag, and copying the Secret ID instead of the Value.

Keysquid team · Updated · Checked against Microsoft Learn (Microsoft Graph, Azure CLI and Entra ID docs) on December 2, 2026

How to rotate Microsoft Entra ID (Azure) keys with Keysquid

Automatic Keysquid creates, verifies, distributes and revokes Microsoft Entra ID client secret keys on a schedule, with no one in the loop. Client secrets on an Entra ID (Azure AD) app registration — added and removed through Microsoft Graph, so old and new overlap.

Setup, as the app shows it:

  1. Register an app named “Keysquid rotator” and give it the Microsoft Graph application permission Application.ReadWrite.OwnedBy (admin consent required).
  2. On each app registration Keysquid should rotate, add the rotator's service principal under Owners. OwnedBy limits Keysquid to exactly those apps.
  3. Create a client secret for the rotator and paste it here. Rotate it yourself, or add the rotator app as its own key in Keysquid.
  • Writes to: Client ID (default variable AZURE_CLIENT_ID), Client secret (default variable AZURE_CLIENT_SECRET), Tenant ID (default variable AZURE_TENANT_ID), in every platform and secret store you map it to.
  • Interval: from every 1 hour to every 4 weeks, subject to your plan’s minimum.
  • Limits Keysquid applies: Entra ID expires every client secret on its own (default 180 days here).
  • Inventory: Keysquid lists every Microsoft Entra ID client secret key the connection can see, including keys it doesn’t manage, with names and last use.

Every rotation runs in the same order: create the new key, verify it, write it everywhere, redeploy where a platform needs it, and only then revoke the previous key after a grace period. If any write fails, everything written so far is restored and the new key is revoked. The value is encrypted to the agent you run, so Keysquid’s servers never see it.

Under the hood: Microsoft Entra ID (Azure) keys in detail

Everything below is what Keysquid handles for you on every rotation. It’s here so you know exactly what happens to your keys, and in case you ever need to do a step by hand.

Where
Entra admin center → App registrations → your app → Certificates & secrets → Client secrets → New client secret.
Expiry
Always set. The portal offers 180, 365 or 730 days or a custom date. Graph defaults to 2 years, the az CLI to 1 year.
Shown once
Copy the Value before leaving the page. The Secret ID next to it is not the secret.
Overlap
Yes: an app registration can hold several secrets, all valid until their own end dates.
When expired
Token requests fail with AADSTS7000222: The provided client secret keys for app ... are expired.
Can't extend
An existing secret's end date can't be changed. Renewing always means adding a new secret.
By API
Microsoft Graph addPassword and removePassword on the application. Least privilege: Application.ReadWrite.OwnedBy.
Keysquid
Automatic: adds a new secret with an end date, deploys it, and removes the old one through Microsoft Graph.

Rotate a client secret in the Entra admin center

  1. Sign in to the Microsoft Entra admin center and open App registrations. Pick the app and note its Application (client) ID.
  2. Open Certificates & secrets → Client secrets. Note the old secret’s description, Secret ID and expiry date; that’s how you’ll recognise it later.
  3. Click New client secret, give it a description that names the service and month, choose an expiry and click Add.
  4. Copy the Value straight into your secret store. It’s shown only once; if you lose it, add another secret.
  5. Update AZURE_CLIENT_SECRET (or your app’s equivalent) everywhere it’s used and restart or redeploy.
  6. Check the sign-in logs (below) until no sign-ins use the old secret’s key ID, then come back and delete the old secret.

Value, not Secret ID. The Secret ID column is a GUID that identifies the secret (Graph calls it keyId). Paste it as the secret and sign-in fails with AADSTS7000215: Invalid client secret provided, whose message itself says to send the client secret value, not the client secret ID.

Rotate with the az CLI without deleting the other secrets

az ad app credential reset is the command most guides show, and its default is destructive. Microsoft’s reference says that by default it clears all passwords and keys on the app and generates one new password. Every other service using a different secret on that app stops working at once. Add --append to add a secret instead.

APP_ID=00000000-0000-0000-0000-000000000000   # Application (client) ID

# 1. See the current secrets: keyId, displayName, hint and endDateTime
az ad app credential list --id "$APP_ID" -o table

# 2. Add a new secret WITHOUT removing the others (note --append)
az ad app credential reset --id "$APP_ID" --append \
  --display-name "web-app 2026-12" --end-date 2027-06-01 --query password -o tsv

# 3. After the switch is confirmed, remove the old secret by its keyId
az ad app credential delete --id "$APP_ID" --key-id "$OLD_KEY_ID"

Without --end-date or --years, the CLI gives the new secret one year. The output of step 2 is the secret itself; pipe it straight into your secret store rather than your terminal history. Run az ad app credential list before and after to be sure the old secret is still there until you remove it.

Rotate with Microsoft Graph

The az CLI calls these endpoints for you. Call them directly from automation, using an app that has the Graph application permission Application.ReadWrite.OwnedBy and is listed as an owner of the apps it rotates. That limits it to exactly those apps, unlike Application.ReadWrite.All.

G=https://graph.microsoft.com/v1.0

# Add a secret that ends in 180 days. The response holds secretText (shown once) and keyId.
curl -s -X POST "$G/applications(appId='$APP_ID')/addPassword" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{"passwordCredential":{"displayName":"web-app 2026-12","endDateTime":"2027-05-31T00:00:00Z"}}' \
  | jq -r '.keyId, .secretText'

# List secrets and their end dates
curl -s "$G/applications(appId='$APP_ID')?\$select=passwordCredentials" -H "Authorization: Bearer $TOKEN" \
  | jq '.passwordCredentials[] | {keyId, displayName, hint, endDateTime}'

# Remove the old secret (204 No Content on success)
curl -s -X POST "$G/applications(appId='$APP_ID')/removePassword" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -d '{"keyId":"'"$OLD_KEY_ID"'"}'

If you leave out endDateTime, Graph sets it to two years after the start. secretText is between 16 and 64 characters and can’t be retrieved again. The hint is its first few characters, the same ones the portal shows.

Confirm the switch in the sign-in logs

Microsoft’s own renewal steps end with this check, and it’s the reliable way to know when the old secret is safe to delete. In the Entra admin center, open Sign-in logs and switch to the service principal sign-ins tab. Each sign-in by your app shows the credential key ID it used. Once every recent sign-in shows the new secret’s key ID and none shows the old one, remove the old secret.

Which lifetime to choose, and who sets the limits

Where the secret is createdDefault end dateWhat you can choose
Entra admin centerNone preselected180, 365 or 730 days, or a custom date
az ad app credential reset1 year--years or --end-date
Graph addPassword2 years after the startendDateTime

Defaults from the Azure CLI reference and the Microsoft Graph addPassword reference. An app management policy in your tenant can block new client secrets or limit their lifetime, whatever the tool.

Shorter is safer only if something rotates the secret for you. A 180-day secret that relies on a calendar reminder is an outage every six months. Entra ID also shows a Renew expiring application credentials recommendation (under Entra ID → Overview → Recommendations) for credentials that end within 30 days, which is a useful backstop but not a schedule.

If the secret already expired

  1. Add a new secret as above. Nothing needs to be “unexpired”; the app registration itself is fine.
  2. Update every place that holds the old value. Services that cache the credential separately need their own step: an AKS cluster using a service principal, for example, needs az aks update-credentials.
  3. Remove the expired secret so the list only shows credentials in use.

When a client secret is the wrong tool

Microsoft recommends certificates over client secrets for production apps, and managed identities or federated identity credentials where the workload runs somewhere that supports them (Azure resources, GitHub Actions, Kubernetes). Those have no secret to leak or rotate, and they’re the better choice when available. Client secrets remain the practical option for apps running outside Azure that can’t use federation; that’s where rotation matters.

By hand vs. with Keysquid

By hand

  1. Add a secret with --append and copy the Value once.
  2. Update every app, pipeline and cluster that uses it.
  3. Check sign-in logs, then remove the old secret.
  4. Repeat before the new end date.

With Keysquid

  1. Keysquid adds a new secret with the end date you set.
  2. It writes the client ID, secret and tenant ID to every platform you mapped and redeploys.
  3. It removes the old secret after the grace period.
  4. It lists every secret on the app with its end date.

What Keysquid does on every rotation

You register one small “Keysquid rotator” app with Application.ReadWrite.OwnedBy and add it as an owner of each app registration it should rotate. Keysquid then calls addPassword with an end date (180 days unless you choose another), deploys the new value as AZURE_CLIENT_SECRET alongside AZURE_CLIENT_ID and AZURE_TENANT_ID, and calls removePassword on the old secret after the grace period. It never touches other secrets on the app. It doesn’t rotate certificates or federated credentials.

Frequently asked questions

Can I extend an Azure client secret's expiry date?

No. A client secret's end date is fixed when it's created. Add a new secret, move your apps to it and remove the old one.

Does az ad app credential reset delete my other secrets?

Yes, by default. The Azure CLI reference says it clears all passwords and keys on the app. Add --append to add a new secret and keep the existing ones.

What does AADSTS7000222 mean?

The client secret your app sent has passed its end date. Create a new client secret for the app registration and update the app; the registration itself doesn't need changing.

Why does my new client secret give AADSTS7000215?

Usually because the Secret ID was copied instead of the Value. The Value is shown only once when you create the secret; if you didn't copy it, add another secret.

How long should an Azure client secret last?

As short as your rotation can reliably handle. The portal offers 180, 365 or 730 days. Without automation, a long expiry just postpones the outage; with automation, 180 days or less is easy.

How do I know when the old secret is safe to delete?

Check the service principal sign-ins in the Entra sign-in logs. Each sign-in shows the credential key ID used. When none show the old key ID, remove it.

Sources

  1. Microsoft Graph: application addPassword
  2. Microsoft Graph: application removePassword
  3. Azure CLI reference: az ad app credential
  4. Microsoft Entra: Renew expiring application credentials
  5. Microsoft.Identity.Web: Use client secrets
  6. Microsoft Entra: Enforce secret and certificate standards
  7. Azure troubleshooting: AADSTS7000222 expired client secret
Rotate an Azure Client Secret (Entra ID) Before It Expires