# Revoking a client secret does not stop the token it already issued

> A real Entra test: tokens kept reading users after the client secret was revoked. Disabling the service principal cut them off in about two minutes.

- URL: https://iamops.dev/entra-revoked-secret-token-still-works/
- Language: en
- Author: Argo
- Published: 2026-11-29
- Category: Labs
- Depth: Practitioner
- Audience: Engineers and operators
- Time: 12 min
- Topics: Entra ID, Client credentials, Token revocation, Secrets, Labs

## TL;DR

- After the client secret is revoked, a [new token request fails](https://iamops.dev/entra-revoked-secret-token-still-works/#after-the-revoke) with invalid_client, but tokens already issued still read users.
- [Disabling the service principal](https://iamops.dev/entra-revoked-secret-token-still-works/#disable-the-service-principal) stopped Microsoft Graph accepting those tokens within about two minutes.
- Removing the [app's role](https://iamops.dev/entra-revoked-secret-token-still-works/#limit-the-risk) did not affect an issued token during the three minutes I watched.
- A client that asks for it gets a [token that lasts about a day](https://iamops.dev/entra-revoked-secret-token-still-works/#a-token-that-lasts-a-day), and a managed identity token does too.
- Deleting a [managed identity](https://iamops.dev/entra-revoked-secret-token-still-works/#managed-identity-with-no-secret) cut off its token in under two minutes.

**Audience: Practitioners.** You build or run an app that signs in to Microsoft Entra <abbr title="identifier">ID</abbr> with a client secret. This lab answers one question: after a leak, what actually stops a token someone already took?

**The answer:** revoking the secret does not. It stops new tokens, and the ones already issued keep reading data from Microsoft Graph. In my runs, disabling the app's service principal stopped them within about two minutes.

## Setup

You need a throwaway tenant, the Azure command-line interface (CLI), `curl` and `jq`. Never use a work or production tenant. Sign in with `az login --tenant "$TENANT_ID" --allow-no-subscriptions` and set two variables:

```bash
export TENANT_ID=<TENANT_ID>
export APP_NAME=lab-revoke-token-test
```

Create the app and its service principal:

```bash
export APP_ID=$(az ad app create --display-name "$APP_NAME" --sign-in-audience AzureADMyOrg --query appId -o tsv)
az ad sp create --id "$APP_ID" --query id -o tsv
echo "$APP_ID"
```

The app needs one permission for the test to mean anything: `User.Read.All`, an application permission on Microsoft Graph. I assigned the role directly to the service principal, because admin consent through the <abbr title="command-line interface">CLI</abbr> left my tokens without it:

```bash
GRAPH_ID=$(az ad sp list --display-name "Microsoft Graph" --query "[0].appId" -o tsv)
READ_ROLE=$(az ad sp show --id "$GRAPH_ID" --query "appRoles[?value=='User.Read.All'].id | [0]" -o tsv)
az ad app permission add --id "$APP_ID" --api "$GRAPH_ID" --api-permissions "$READ_ROLE=Role"
APP_SP=$(az ad sp show --id "$APP_ID" --query id -o tsv)
GRAPH_SP=$(az ad sp show --id "$GRAPH_ID" --query id -o tsv)
az rest --method post --uri "https://graph.microsoft.com/v1.0/servicePrincipals/$APP_SP/appRoleAssignments" --headers "Content-Type=application/json" --body "{\"principalId\":\"$APP_SP\",\"resourceId\":\"$GRAPH_SP\",\"appRoleId\":\"$READ_ROLE\"}"
az ad app permission list --id "$APP_ID" --query "[].resourceAccess[].type" -o tsv
sleep 60
```

Then create a client secret that expires in seven days, written to a file only your user can read:

```bash
umask 077
END=$(date -u -v+7d +%Y-%m-%d)
az ad app credential reset --id "$APP_ID" --append --display-name lab --end-date "$END" --query password -o tsv > secret.value
printf 'ENTRA_APP_SECRET=%s\n' "$(cat secret.value)" > secret.env
rm -f secret.value
source ./secret.env
```

## Get a token

The client credentials flow needs no user sign-in. The token stays in a shell variable, and only a few claims are printed:

```bash
TOKEN=$(curl -s -X POST "https://login.microsoftonline.com/$TENANT_ID/oauth2/v2.0/token" \
  --data-urlencode grant_type=client_credentials \
  --data-urlencode client_id="$APP_ID" \
  --data-urlencode "client_secret=$ENTRA_APP_SECRET" \
  --data-urlencode scope=https://graph.microsoft.com/.default | jq -r .access_token)
echo "$TOKEN" | cut -d. -f2 | tr '_-' '/+' | jq -R '@base64d | fromjson | {aud, idtyp, roles, lifetime_seconds: (.exp - .iat)}'
```

![Terminal output: the decoded token claims show the Graph audience, the app token type, the User.Read.All role and a lifetime of 3900 seconds.](https://iamops.dev/media/entra-revoked-secret-token-still-works/01-token.webp)

*The token. App-only, one read role. The lifetime counted from iat includes five minutes of clock allowance.*

## A token that lasts a day

An app can tell Entra that it handles <abbr title="Continuous Access Evaluation">CAE</abbr>, by sending the `cp1` client capability. The same secret then buys a token that lasts about 24 hours. Whoever holds the secret decides whether to ask for it.

```bash
curl -s -o long.json -X POST "https://login.microsoftonline.com/$TENANT_ID/oauth2/v2.0/token" \
  --data-urlencode grant_type=client_credentials \
  --data-urlencode client_id="$APP_ID" \
  --data-urlencode "client_secret=$ENTRA_APP_SECRET" \
  --data-urlencode scope=https://graph.microsoft.com/.default \
  --data-urlencode 'claims={"access_token":{"xms_cc":{"values":["cp1"]}}}'
jq '{expires_in}' long.json
LONG_TOKEN=$(jq -r .access_token long.json); rm -f long.json
```

## Read users before the revoke

I called Graph with both tokens. A small function prints the status and the number of users, so no names or IDs leave the terminal:

```bash
users() { curl -s -o resp.json -w "$1 HTTP %{http_code} " -H "Authorization: Bearer $2" "https://graph.microsoft.com/v1.0/users?\$top=5&\$select=id"; jq -r '.error.code // "users: \(.value | length)"' resp.json; }
users short "$TOKEN"
users long "$LONG_TOKEN"
```

Both returned `HTTP 200` and five users.

## Revoke the secret

This is the step a team takes after a leak:

```bash
KEY_ID=$(az ad app show --id "$APP_ID" --query "passwordCredentials[0].keyId" -o tsv)
az ad app credential delete --id "$APP_ID" --key-id "$KEY_ID"
echo "secrets left: $(az ad app show --id "$APP_ID" --query "length(passwordCredentials)" -o tsv)"
```

## After the revoke

First a new token request with the old secret, then both old tokens:

```bash
curl -s -o new.json -w "HTTP %{http_code}\n" -X POST "https://login.microsoftonline.com/$TENANT_ID/oauth2/v2.0/token" \
  --data-urlencode grant_type=client_credentials \
  --data-urlencode client_id="$APP_ID" \
  --data-urlencode "client_secret=$ENTRA_APP_SECRET" \
  --data-urlencode scope=https://graph.microsoft.com/.default
jq -r '"error=\(.error)"' new.json
users short "$TOKEN"
users long "$LONG_TOKEN"
```

![Terminal output: both tokens read users, the secret is removed, a new token request returns 401 invalid_client, and both old tokens still return HTTP 200 with five users.](https://iamops.dev/media/entra-revoked-secret-token-still-works/02-revoke.webp)

*The revoke. No new tokens, but both old ones still work.*

The new request got `HTTP 401` with `invalid_client`. Both old tokens got `HTTP 200`.

## Disable the service principal

Disabling sign-in for the service principal is a different switch. I set it and read users with both tokens every 30 seconds:

```bash
APP_SP=$(az ad sp show --id "$APP_ID" --query id -o tsv)
az rest --method patch --uri "https://graph.microsoft.com/v1.0/servicePrincipals/$APP_SP" \
  --headers "Content-Type=application/json" --body '{"accountEnabled":false}'
for i in $(seq 1 10); do
  date -u +%H:%M:%S
  users short "$TOKEN"
  users long "$LONG_TOKEN"
  sleep 30
done
```

![Terminal output: after the service principal is disabled both tokens still work for the first checks, then the ordinary token and later the long-lived token return 401 Authorization_IdentityDisabled.](https://iamops.dev/media/entra-revoked-secret-token-still-works/03-disable.webp)

*The cut-off. The ordinary token was refused after about one minute, the long-lived one after about two.*

Graph refused the ordinary token after about one minute and the long-lived token after about two, with `Authorization_IdentityDisabled`. An earlier run refused both after about 90 seconds. Microsoft documents this revocation for CAE tokens on Microsoft Graph; in my runs Graph refused the ordinary token too. An <abbr title="application programming interface">API</abbr> that only checks a token's signature and expiry has no way to know the app was disabled, so test your own APIs.

## Limit the risk

A leak does not need a mistake in a repository: [infostealers now copy the tokens and API keys of AI coding tools](https://iamops.dev/infostealer-identities-ai-agents/) straight from developer laptops. If a secret leaks, do these in order: disable the service principal, remove the secret, then look at the sign-in log before you enable the app again.

- **Disable the service principal.** Stops new tokens and, on Microsoft Graph, the issued ones. It also stops the real app, so plan the outage.
- **Remove the secret.** Stops new tokens only. Needed anyway, so the leaked value is useless after you re-enable the app.
- **Remove the app's role.** An issued token carries its roles inside it. After I removed the assignment, both tokens still read users for the three minutes I watched.
- **Delete the app.** Also ends access, though answers alternated for a short while in my run. It is harder to undo than disabling.
- **Short secret expiry.** Limits how long a forgotten secret works. A one-day secret behaved like the seven-day one: revoking it left the issued token working.
- **Token lifetime policy.** The policy follows the API that receives the token, not the app that asks for it. A ten-minute policy on my client app did not change its Graph token. Set it on your own APIs.
- **No secret at all.** A [federated credential](https://iamops.dev/secrets-vs-federated-credentials/) or a managed identity leaves nothing to copy from a file or a repository. A stolen token is still a token.
- **Watch the sign-ins.** Service principal sign-ins appear in the Graph sign-in log with the caller's <abbr title="Internet Protocol">IP</abbr> address, a few minutes late. Reading it needs Entra ID P1 or higher. Alert on an address the app never used before.
- **Restrict where the app signs in from.** Conditional Access for workload identities can block by location. It needs Workload Identities Premium.

## Managed identity, with no secret

I repeated the question with a user-assigned managed identity on an Azure Container Instance, with the same read role. A [small probe script](https://iamops.dev/lab-files/entra-revoked-secret-token-still-works/probe.py) inside the container kept the first token and used it every 30 seconds.

```bash
az group create -n rg-lab-revoke-mi -l <REGION>
az identity create -g rg-lab-revoke-mi -n lab-revoke-mi
# assign User.Read.All to the identity's principalId, as in the setup above
az container create -g rg-lab-revoke-mi -n lab-revoke-probe --image mcr.microsoft.com/azurelinux/base/python:3.12 \
  --os-type Linux --cpu 1 --memory 1 --restart-policy Never --assign-identity <IDENTITY_ID> \
  --environment-variables MI_CLIENT_ID=<CLIENT_ID> PROBE="$(base64 < probe.py | tr -d '\n')" \
  --command-line "python3 -c 'import os,base64;exec(base64.b64decode(os.environ[\"PROBE\"]))'"
az identity delete -g rg-lab-revoke-mi -n lab-revoke-mi
az container logs -g rg-lab-revoke-mi -n lab-revoke-probe
az group delete -n rg-lab-revoke-mi --yes
```

![Terminal output: the managed identity token lasts 86700 seconds and reads users; after the identity is deleted Graph returns 401 while the identity endpoint still hands out the same token.](https://iamops.dev/media/entra-revoked-secret-token-still-works/05-managed-identity.webp)

*Managed identity. A day-long token, refused soon after the identity was deleted.*

The token's lifetime was 86,700 seconds. Graph refused it right after the deletion, let one more call through about a minute later, and refused every call from about 95 seconds on. For several minutes the identity endpoint kept returning the same cached token, then it started returning errors. Microsoft states that CAE for workload identities does not cover managed identities, so treat this as what I observed on Graph, not as a promise.

## Cleanup

Delete the app and its service principal, then check with separate queries:

```bash
az ad app delete --id "$APP_ID"
az ad app list --display-name "$APP_NAME" --query "length(@)" -o tsv
az ad sp list --display-name "$APP_NAME" --query "length(@)" -o tsv
rm -f secret.env new.json resp.json
unset TOKEN LONG_TOKEN ENTRA_APP_SECRET
```

![Terminal output: the lab app is deleted and two queries return zero apps and zero service principals with its name.](https://iamops.dev/media/entra-revoked-secret-token-still-works/04-cleanup.webp)

*Removed. No app and no service principal left.*

Entra keeps a deleted app for 30 days, so it can still be restored from the portal.

## Repeat it

The [lab steps](#repeat-it) run the same commands in order, with the expected output after each one. I ran them in one session before publishing. Keep the values in your shell, and never print the secret or a token.

*Written by Argo. The runs were on 29 November 2026 in a personal Entra test tenant, with apps and one identity created for the lab and one read permission. All of them were removed afterwards. The values in the commands are placeholders.*

## Repeat this lab

Needs a throwaway Entra tenant, the Azure CLI, curl and jq, and an account that can create app registrations and assign Microsoft Graph application roles. It creates one app with one read permission (User.Read.All) and one client secret, gets two tokens, revokes the secret, shows that both tokens still read users, then disables the service principal and watches them stop. About 15 minutes. Never use a work or production tenant.

Every value in angle brackets is a placeholder for your own test environment. Nothing on this page is a real identifier or secret.

**Set your variables once** `env.sh` (bash)

```bash
export TENANT_ID=<TENANT_ID>
export APP_NAME=lab-revoke-token-test
```

### Step 1: Create the app and its service principal

**Goal.** One app registration and the service principal that lets it sign in.

**Prerequisites**

- Throwaway tenant, Azure CLI signed in with az login --tenant "$TENANT_ID" --allow-no-subscriptions

`app.sh` (bash)

```bash
export APP_ID=$(az ad app create --display-name "$APP_NAME" --sign-in-audience AzureADMyOrg --query appId -o tsv)
az ad sp create --id "$APP_ID" --query id -o tsv
echo "$APP_ID"
```

**Expected output**

```text
<SERVICE_PRINCIPAL_ID>
<APP_ID>
```

### Step 2: Add the Graph read permission and assign the role

**Goal.** User.Read.All as an application permission, looked up by name, then assigned to the service principal. Wait a minute before asking for a token so the assignment is in place.

**Prerequisites**

- The app step printed an APP_ID

`permission.sh` (bash)

```bash
GRAPH_ID=$(az ad sp list --display-name "Microsoft Graph" --query "[0].appId" -o tsv)
READ_ROLE=$(az ad sp show --id "$GRAPH_ID" --query "appRoles[?value=='User.Read.All'].id | [0]" -o tsv)
az ad app permission add --id "$APP_ID" --api "$GRAPH_ID" --api-permissions "$READ_ROLE=Role"
APP_SP=$(az ad sp show --id "$APP_ID" --query id -o tsv)
GRAPH_SP=$(az ad sp show --id "$GRAPH_ID" --query id -o tsv)
az rest --method post --uri "https://graph.microsoft.com/v1.0/servicePrincipals/$APP_SP/appRoleAssignments" --headers "Content-Type=application/json" --body "{\"principalId\":\"$APP_SP\",\"resourceId\":\"$GRAPH_SP\",\"appRoleId\":\"$READ_ROLE\"}"
az ad app permission list --id "$APP_ID" --query "[].resourceAccess[].type" -o tsv
sleep 60
```

**Expected output**

```text
Role
```

### Step 3: Create a 7-day client secret

**Goal.** A client secret the app can use to ask for a token. Keep the value in a file only you can read; never print it.

**Prerequisites**

- The app step printed an APP_ID

`secret.sh` (bash)

```bash
umask 077
END=$(date -u -v+7d +%Y-%m-%d)
az ad app credential reset --id "$APP_ID" --append --display-name lab --end-date "$END" --query password -o tsv > secret.value
printf 'ENTRA_APP_SECRET=%s\n' "$(cat secret.value)" > secret.env
rm -f secret.value
source ./secret.env
```

**Expected output**

```text
(no output: the value is written to secret.env, mode 600)
```

### Step 4: Request a token and read its claims

**Goal.** The client-credentials request, then the claims of the access token. The roles claim should list User.Read.All. The token itself stays in a shell variable.

**Prerequisites**

- The secret step sourced secret.env

`token.sh` (bash)

```bash
TOKEN=$(curl -s -X POST "https://login.microsoftonline.com/$TENANT_ID/oauth2/v2.0/token" \
  --data-urlencode grant_type=client_credentials \
  --data-urlencode client_id="$APP_ID" \
  --data-urlencode "client_secret=$ENTRA_APP_SECRET" \
  --data-urlencode scope=https://graph.microsoft.com/.default | jq -r .access_token)
echo "$TOKEN" | cut -d. -f2 | tr '_-' '/+' | jq -R '@base64d | fromjson | {aud, idtyp, roles, lifetime_seconds: (.exp - .iat)}'
```

**Expected output**

```json
{
  "aud": "https://graph.microsoft.com",
  "idtyp": "app",
  "roles": [
    "User.Read.All"
  ],
  "lifetime_seconds": 3900
}
```

### Step 5: Ask for a long-lived token

**Goal.** The same request with the cp1 client capability, which opts in to Continuous Access Evaluation. Entra answers with a token that lasts about a day.

**Prerequisites**

- The secret step sourced secret.env

`long.sh` (bash)

```bash
curl -s -o long.json -X POST "https://login.microsoftonline.com/$TENANT_ID/oauth2/v2.0/token" \
  --data-urlencode grant_type=client_credentials \
  --data-urlencode client_id="$APP_ID" \
  --data-urlencode "client_secret=$ENTRA_APP_SECRET" \
  --data-urlencode scope=https://graph.microsoft.com/.default \
  --data-urlencode 'claims={"access_token":{"xms_cc":{"values":["cp1"]}}}'
jq '{expires_in}' long.json
LONG_TOKEN=$(jq -r .access_token long.json); rm -f long.json
```

**Expected output**

```text
{
  "expires_in": 86399
}
```

### Step 6: Read users with both tokens before revoking

**Goal.** Call Microsoft Graph with each token. Only the count is printed.

**Prerequisites**

- The token step set TOKEN

`replay.sh` (bash)

```bash
users() { curl -s -o resp.json -w "$1 HTTP %{http_code} " -H "Authorization: Bearer $2" "https://graph.microsoft.com/v1.0/users?\$top=5&\$select=id"; jq -r '.error.code // "users: \(.value | length)"' resp.json; }
users short "$TOKEN"
users long "$LONG_TOKEN"
```

**Expected output**

```text
short HTTP 200 users: 5
long HTTP 200 users: 5
```

### Step 7: Revoke the secret

**Goal.** Delete the client secret. This is the step a team takes after a leak.

**Prerequisites**

- The secret step created a secret for APP_ID

`revoke.sh` (bash)

```bash
KEY_ID=$(az ad app show --id "$APP_ID" --query "passwordCredentials[0].keyId" -o tsv)
az ad app credential delete --id "$APP_ID" --key-id "$KEY_ID"
echo "secrets left: $(az ad app show --id "$APP_ID" --query "length(passwordCredentials)" -o tsv)"
```

**Expected output**

```text
secrets left: 0
```

### Step 8: Ask for a new token, then read users with the old ones

**Goal.** A new token needs the secret, so it fails. The tokens issued before the revoke still read users.

**Prerequisites**

- The revoke step removed the secret

`after.sh` (bash)

```bash
curl -s -o new.json -w "HTTP %{http_code}\n" -X POST "https://login.microsoftonline.com/$TENANT_ID/oauth2/v2.0/token" \
  --data-urlencode grant_type=client_credentials \
  --data-urlencode client_id="$APP_ID" \
  --data-urlencode "client_secret=$ENTRA_APP_SECRET" \
  --data-urlencode scope=https://graph.microsoft.com/.default
jq -r '"error=\(.error)"' new.json
users short "$TOKEN"
users long "$LONG_TOKEN"
```

**Expected output**

```text
HTTP 401
error=invalid_client
short HTTP 200 users: 5
long HTTP 200 users: 5
```

### Step 9: Disable the service principal and watch both tokens

**Goal.** Switch off sign-in for the app's service principal, then read users every 30 seconds. Answers can alternate for a minute or two while the change spreads.

**Prerequisites**

- The after-revoke step showed both tokens still working

`disable.sh` (bash)

```bash
APP_SP=$(az ad sp show --id "$APP_ID" --query id -o tsv)
az rest --method patch --uri "https://graph.microsoft.com/v1.0/servicePrincipals/$APP_SP" \
  --headers "Content-Type=application/json" --body '{"accountEnabled":false}'
for i in $(seq 1 10); do
  date -u +%H:%M:%S
  users short "$TOKEN"
  users long "$LONG_TOKEN"
  sleep 30
done
```

**Expected output**

```text
01:25:03
short HTTP 200 users: 5
long HTTP 200 users: 5
01:25:33
short HTTP 200 users: 5
long HTTP 200 users: 5
01:26:04
short HTTP 401 Authorization_IdentityDisabled
long HTTP 200 users: 5
...
01:29:36
short HTTP 401 Authorization_IdentityDisabled
long HTTP 401 InvalidAuthenticationToken
```

### Step 10: Delete the app and check nothing is left

**Goal.** Delete the app registration and its service principal, then check with separate queries.

**Prerequisites**

- The app step created APP_ID

`cleanup.sh` (bash)

```bash
az ad app delete --id "$APP_ID"
az ad app list --display-name "$APP_NAME" --query "length(@)" -o tsv
az ad sp list --display-name "$APP_NAME" --query "length(@)" -o tsv
rm -f secret.env new.json resp.json
unset TOKEN LONG_TOKEN ENTRA_APP_SECRET
```

**Expected output**

```text
0
0
```


## Sources

- [Microsoft Learn, Continuous access evaluation for workload identities](https://learn.microsoft.com/en-us/entra/identity/conditional-access/concept-continuous-access-evaluation-workload)
- [Microsoft Learn, OAuth 2.0 client credentials flow on the Microsoft identity platform](https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-client-creds-grant-flow)
- [Microsoft Learn, Configurable token lifetimes in Microsoft Entra ID](https://learn.microsoft.com/en-us/entra/identity-platform/configurable-token-lifetimes)

Discuss: [X](https://x.com/iamopsdev) | [LinkedIn](https://www.linkedin.com/company/iamops-dev/)
