Cloud and hosting

Azure (Microsoft Entra app client secrets) API keys: find, store, rotate, and use them safely with AI agents

Last checked 2026-10-25 against Azure (Microsoft Entra app client secrets)'s documentation

An Azure service principal signs in with a client secret created in the Microsoft Entra admin center under Entra ID → App registrations → your app → Certificates & secrets → Client secrets → New client secret. The secret value is shown only once and a client secret lasts at most 24 months. Microsoft recommends certificates or federated credentials instead of secrets in production.

Azure (Microsoft Entra app client secrets) key types

TypePrefixSecret?ScopeExpiry
Client secret
Copy the secret Value, not the Secret ID. The Value is never displayed again after you leave the page.
—YesThe Azure roles assigned to the app's service principalMaximum 24 months; Microsoft recommends under 12 months
Certificate credential
Recommended by Microsoft over client secrets. The public certificate is uploaded; the private key stays with you.
—YesThe Azure roles assigned to the app's service principalSet by the certificate's expiry date

How to create a Azure (Microsoft Entra app client secrets) key

  1. Sign in to the Microsoft Entra admin center.
  2. Browse to Entra ID → App registrations and select your application.
  3. Select Certificates & secrets → Client secrets → New client secret.
  4. Add a description and choose an expiration (or custom lifetime, up to 24 months), then select Add.
  5. Copy the secret Value immediately; it is not shown again.

Open Azure (Microsoft Entra app client secrets)'s key settings

Limiting what the key can do

A client secret has no scopes of its own; it authenticates the app, and access is set by the Azure roles assigned to the service principal (for example on a subscription, resource group or single resource) and by API permissions granted to the app. Assign the narrowest built-in role at the narrowest scope.

How to rotate a Azure (Microsoft Entra app client secrets) key

  1. In the app registration, add a new client secret under Certificates & secrets (multiple secrets can exist at once).
  2. Update your application or pipeline with the new secret value.
  3. Delete the old secret once nothing uses it.

Azure DevOps service connections that created the principal automatically must have the secret updated from the Azure DevOps portal instead.

How to revoke a Azure (Microsoft Entra app client secrets) key

  1. In the Entra admin center open the app registration and select Certificates & secrets.
  2. Delete the client secret you want to revoke.

If your Azure (Microsoft Entra app client secrets) key leaked

  1. Add a replacement secret and update the application.
  2. Delete the exposed client secret from the app registration.
  3. Review the service principal's role assignments and sign-in activity, and consider replacing the secret with a certificate or federated credential.

Environment variables and CLI

Azure CLI (az): az login --service-principal --username APP_ID --password CLIENT_SECRET --tenant TENANT_ID (or --certificate with a PEM file)

Things that catch people out

  • The secret Value is shown only once; the Secret ID is not a credential.
  • Secrets expire (24 months at most), so apps break silently on the expiry date unless you track it.
  • Microsoft says client secrets should not be used in production; prefer certificates, federated credentials or managed identities.

Common Azure (Microsoft Entra app client secrets) authentication errors

AADSTS7000215: Invalid client secret is provided.

The app is signing in with a wrong or incorrect secret. A common cause is using the secret ID instead of the secret value.

AADSTS7000222: InvalidClientSecretExpiredKeysProvided - The provided client secret keys are expired.

The client secret has passed its expiry date.

Recent incidents that put Azure (Microsoft Entra app client secrets) keys at risk

If you were affected by one of these, rotate your Azure (Microsoft Entra app client secrets) keys using the rotation steps above.

Using your Azure (Microsoft Entra app client secrets) key with AI agents

A coding agent that can read your .env file or your shell history can read the key, and anything in its context can end up in logs, transcripts or a prompt-injected request. The safer pattern is to keep the key in a credential broker that performs the authenticated step for the agent and hands back only the result.

BotPassword works this way. For a Azure (Microsoft Entra app client secrets) key, these intents fit:

IntentWhat BotPassword does
list_credentialsLists the credentials this agent is granted and what it may do with each. Never values.
run_withRuns a command with the key injected as an environment variable or a 0600 temporary file, never on the command line, and redacts the key from the output.
cli_loginLets git, Docker, the AWS CLI and kubectl log in through bpw's credential helper, so the token is fetched when the tool needs it and not written into its config. The helper hands the value to the tool, so the grant is always disclosing. Other tools use run_with; OAuth device logins are planned.
rotatePartly built: creates a new key, stores it as pending, verifies it, promotes it, then revokes the old key after a grace period. Today it works for Cloudflare tokens and AWS IAM keys you have set up, and an agent can start it only under a grant with autopilot; other providers cannot be rotated through their API yet.
store_secretSaves a value the agent already holds as a new vault item.
capture_secretPlanned, not built yet: will read a newly created key straight from the page or command output into the vault.

Azure (Microsoft Entra app client secrets) also publishes its own MCP server. Whatever server the agent uses, keep the credential it authenticates with out of the agent's context.

Set it up in your agent: Aider · Amp · Claude Code · Claude Desktop · Cline · OpenAI Codex CLI · all agents

Frequently asked questions

Where do I find my Azure client secret?

You can't view it again after creation. In Entra ID → App registrations → your app → Certificates & secrets, only the Secret ID and expiry are listed, so create a new secret if the value is lost.

How long does an Azure client secret last?

At most 24 months, and Microsoft recommends setting under 12 months.

How do I log in to Azure CLI with a service principal?

Run az login --service-principal --username APP_ID --password CLIENT_SECRET --tenant TENANT_ID.

What does AADSTS7000215 mean?

It means the client secret supplied is invalid, often because the secret ID was used instead of the secret value.

Can an AI agent use my Azure (Microsoft Entra app client secrets) key without seeing it?

Yes, if the key never enters the agent's context. Instead of pasting the key into a chat or leaving it in a .env file the agent can read, keep it in a credential broker that injects it into the command or request on the agent's behalf. BotPassword does this with list_credentials, run_with, store_secret, so the agent gets the result and never the value.

Stop pasting Azure (Microsoft Entra app client secrets) keys into agents

BotPassword is in early access. Request an invite and we'll email you when your spot opens.