# Token lifecycle and logout

This page covers introspection, revocation, and browser end-session behavior.
For refresh package rotation and the M7 acknowledgement lifecycle, see
[Token endpoint](https://m7.org/docs/api/sso.user.m7.org/token.md#refresh-token-exchange) and
[Token acknowledgement](https://m7.org/docs/api/sso.user.m7.org/token-acknowledgement.md).

## Introspection

```text
POST https://sso.user.m7.org/introspect
Content-Type: application/x-www-form-urlencoded
```

Introspection is for a confidential resource server or client that needs the
current state of a token it owns. M7 requires the client's configured token
endpoint authentication method and rejects public (`none`) clients for this
endpoint.

| Field | Required | Description |
| --- | --- | --- |
| `token` | Yes | Token to inspect. |
| `token_type_hint` | No | Hint such as `access_token` or `refresh_token`. |
| `client_id` | Conditional | Required by body-based and JWT client-authentication methods. |

The authenticated client may introspect only a token that carries that exact
OAuth `client_id`. A missing, malformed, or mismatched token `client_id` returns
`insufficient_scope` with HTTP 403.
For `client_secret_jwt` or `private_key_jwt`, the client assertion audience is
either the canonical authorization-server issuer `https://sso.user.m7.org` or
the exact introspection endpoint URL.

Clients registered with `tls_client_auth` or
`self_signed_tls_client_auth` present the registered certificate, send their
exact `client_id`, and use the discovered
`https://mtls-sso.user.m7.org/introspect` alias. Certificate-bound tokens
retain their `cnf."x5t#S256"` constraint; presenting a token without its exact
bound certificate does not make it active.

Example:

```bash
curl --fail-with-body --silent --show-error \
  --request POST 'https://sso.user.m7.org/introspect' \
  --user 'CLIENT_ID:CLIENT_SECRET' \
  --data-urlencode 'token=ACCESS_TOKEN' \
  --data-urlencode 'token_type_hint=access_token'
```

The response contains the token's active state and, when active, its
authoritative metadata. Integrations must treat `active: false` as unusable
and must not rely on a decoded JWT alone to establish active status.
For the public OAuth policy, `active: true` also requires the SHA-256 hash of
the exact presented JWT to match the hash retained with its active Identity
session. Identity retains the hash for this check, not the raw bearer token.
SSO then checks the verified token's complete signed scope and resource-audience
set against the authenticated client's current registration. The audience UUID
matching the verified nested `m7.target_client_id` is issuer-added metadata;
other audience entries still require registration. If any authority was
removed, the response is only `{ "active": false }`. Newly registered scopes
or audiences do not expand an existing token. For an organization-owned
client, `active: true` additionally requires the organization to exist and be
active and non-archived. A missing, disabled, archived, malformed, or
temporarily unverifiable organization state fails closed as `{ "active":
false }`.

```json
{
  "active": true,
  "sub": "SUBJECT_UUID",
  "client_id": "CLIENT_ID",
  "scope": "openid profile",
  "exp": 1786309200
}
```

Exact optional fields depend on the token class and policy. Do not expose an
introspection endpoint to untrusted browser code.

Active responses include `m7` and `act` when present. For Blog → Files exchange,
the caller remains Blog's `client_id`, the actor is Blog and the nested target
is Files. The receiving target cannot use its own credentials to introspect a
token belonging to Blog. Use the
[exchange lifecycle](https://m7.org/docs/api/sso.user.m7.org/token.md#token-exchange-rfc-8693) and applicable connection
verification for delegated permission checks. Local JWT verification alone
does not observe withdrawn connection approval.

## Revocation

```text
POST https://sso.user.m7.org/revoke
Content-Type: application/x-www-form-urlencoded
```

Revocation uses the client's configured authentication method. Public clients
registered with `none` identify themselves with their exact `client_id` and do
not send a secret. Confidential clients may use `client_secret_basic`,
`client_secret_post`, `client_secret_jwt`, `private_key_jwt`,
`tls_client_auth`, or `self_signed_tls_client_auth`. An mTLS client presents
its registered certificate and uses the discovered
`https://mtls-sso.user.m7.org/revoke` alias. Send the token to revoke and an
optional type hint:

| Field | Required | Description |
| --- | --- | --- |
| `token` | Yes | Token to revoke. M7 also accepts `refresh_token` as an alias. |
| `token_type_hint` | No | Hint such as `access_token` or `refresh_token`. |
| `client_id` | Conditional | Required for `none`, body-based, and JWT client authentication; it may also be included with Basic authentication if it matches the Basic identifier. |
| `client_secret` | Conditional | Required for `client_secret_post`. |
| `client_assertion_type` | Conditional | Required for JWT client authentication; use `urn:ietf:params:oauth:client-assertion-type:jwt-bearer`. |
| `client_assertion` | Conditional | Required for JWT client authentication. The audience may be the canonical issuer or exact revocation endpoint URL. |

Example for a public client:

```bash
curl --fail-with-body --silent --show-error \
  --request POST 'https://sso.user.m7.org/revoke' \
  --data-urlencode 'client_id=CLIENT_ID' \
  --data-urlencode 'token=REFRESH_TOKEN' \
  --data-urlencode 'token_type_hint=refresh_token'
```

Example with Basic authentication:

```bash
curl --fail-with-body --silent --show-error \
  --request POST 'https://sso.user.m7.org/revoke' \
  --user 'CLIENT_ID:CLIENT_SECRET' \
  --data-urlencode 'token=REFRESH_TOKEN' \
  --data-urlencode 'token_type_hint=refresh_token'
```

The authenticated client can revoke only its own token. A valid request returns
HTTP `200` with `{}` whether the token was revoked, malformed, expired,
already revoked, or owned by another client. This prevents token-status and
ownership probing. Discard the local token package after a successful
revocation request.

## End session

```text
GET or POST https://sso.user.m7.org/end-session
```

End session is a browser endpoint. Navigate the user to it to offer and
complete sign-out of M7 browser sessions. It accepts these OpenID Connect
logout parameters:

| Parameter | Required | Description |
| --- | --- | --- |
| `id_token_hint` | No | ID token that establishes client context. Strongly recommended. |
| `post_logout_redirect_uri` | No | Exact HTTPS URI registered in this client's `post_logout_redirect_uris`. |
| `state` | No | Value appended to a validated post-logout redirect. |
| `client_id` | Conditional | Required when using `post_logout_redirect_uri` without a valid `id_token_hint`. If both are supplied, it must match the token's client context. |
| `logout_hint` | No | Hint for the logout user experience. |
| `ui_locales` | No | Locale hint for the logout user experience. |

Example:

```text
https://sso.user.m7.org/end-session?
  id_token_hint=ID_TOKEN&
  post_logout_redirect_uri=https%3A%2F%2Fapp.example.com%2Fsigned-out&
  state=LOGOUT_STATE
```

M7 validates the ID token and redirect URI before it exposes a client-scoped
return path. If validation fails, it falls back to generic M7 logout instead
of redirecting to an untrusted URL. The browser page may let the user select
one remembered account or sign out all matching sessions in that browser/context;
this is not an all-devices logout. After confirmed root-family revocation, M7
notifies registered participating applications. Front-channel work uses a bounded
iframe page before navigation; without it, the response redirects with HTTP 303.
The validated return URI retains `state` when supplied.

The account chooser's explicit logout × follows the same notification path.
Ordinary account selection or switching does not. See
[logout notifications](https://m7.org/docs/api/sso.user.m7.org/logout-notifications.md) for participation and receivers.
To revoke another root login without its browser, use
[account session management](https://m7.org/docs/api/api.user.m7.org/sessions),
which sends back-channel notifications only.

## Operational advice

- Revoke credentials when a user disconnects an application, a device is
  lost, or a client secret may be exposed.
- Use introspection for online active-state decisions; cache only within the
  resource server's documented risk tolerance.
- Clear your own application session as part of sign-out. M7 end session does
  not know how to clear cookies or sessions on your domain.
- Do not put refresh tokens, access tokens, or ID tokens in logout telemetry,
  redirect logs, or referrer-bearing URLs beyond the standard `id_token_hint`
  use described here.
