# Token acknowledgement

For browser-direct use the separate
[browser-direct ACK contract](https://m7.org/docs/api/sso.user.m7.org/browser-direct-authentication.md#token-package-and-custody):
send handles and activation ID to `/browser-direct/{CLIENT_ID}/token/ack`, with
a fresh proof targeting `https://id.m7.org/api/v2/oauth/token/ack`. SSO keeps the
activation secret and confirmed predecessor, recovers its saved pending package
before rotating again, and commits selection only after activation. Browsers
cannot choose refresh mode or use the confidential request body below.

`/token/ack` is an M7 extension for an acknowledgement-mode refresh package.
It is not part of base OAuth 2.0. Most integrations should omit `refresh_mode`
and never call this endpoint.

Use this endpoint only when a refresh request explicitly selected `ack` or
`ack_supersede_pending` and returned a package whose `token_state` is
`pending`.

## Why acknowledgement exists

An acknowledgement-mode refresh lets an application durably store a proposed
replacement before the old credential is retired. It is intended for clients
that can safely recover from a process crash or network ambiguity during
rotation.

Both ACK modes share the same activation invariant. If active package `R0`
produces pending package `R1`, `R0` remains active until an ACK successfully
commits a successor. The access and refresh credentials in `R1` are not usable
before that ACK; do not send them to a resource, refresh, or introspection
endpoint.

The pending response contains an activation envelope:

```json
{
  "token_state": "pending",
  "activation": {
    "id": "ACTIVATION_UUID",
    "secret": "ACTIVATION_SECRET"
  },
  "predecessor_bundle": {
    "refresh_token": "PREVIOUS_REFRESH_TOKEN",
    "binding_chain": "PREVIOUS_BINDING_CHAIN",
    "binding_link": "PREVIOUS_BINDING_LINK"
  }
}
```

Persist the entire pending response, including its predecessor bundle, before
attempting acknowledgement. Do not use the pending replacement package before
M7 confirms activation.

## `ack` compared with `ack_supersede_pending`

The modes differ only in how another valid refresh from active `R0` is handled
while a successor is pending:

| Mode | Another `R0` refresh while `R1` is pending | Eligible ACK |
| --- | --- | --- |
| `ack` | Rejects with `refresh_in_progress` (and `retry_after` when available). `R1` remains the one pending proposal. | Only `R1`. Its ACK activates `R1` and revokes `R0`. |
| `ack_supersede_pending` | Issues pending `R2` and, in the same transaction, revokes the never-active `R1`. `R0` remains active. | Only the latest package, `R2`. Its ACK activates `R2` and revokes `R0`; ACK of `R1` is terminally stale. |

```text
ack:
R0 active -> R1 pending
R0 refresh again -> refresh_in_progress
ACK R1 -> R1 active; revoke R0

ack_supersede_pending:
R0 active -> R1 pending
R0 refresh again -> R2 pending; atomically revoke never-active R1
ACK R1 -> activation_not_current
ACK R2 -> R2 active; revoke R0
```

`ack_supersede_pending` is a normal, selectable ACK lifecycle for clients that
prefer a latest-pending policy. It is not a recovery-only mode. It still
requires durable storage and careful concurrency control because each valid
`R0` refresh can make an earlier pending response stale.

Choosing either mode leaves all credential requirements unchanged. The refresh
must authenticate the same client and present active `R0` with its matching
`binding_chain`, `binding_link`, fingerprint when bound, and DPoP proof when
DPoP-bound. ACK requires the pending package's exact activation ID and
activation secret in both modes. A DPoP-bound lineage additionally requires a
fresh proof from the same bound key for every ACK attempt in both modes.

## Request

```text
POST https://sso.user.m7.org/token/ack
Content-Type: application/json
```

The JSON object must contain **only** these fields:

| Field | Required | Description |
| --- | --- | --- |
| `activation_id` | Yes | UUID from `activation.id`. UUID text is case-insensitive. |
| `activation_secret` | Yes | One-time secret from `activation.secret`. |

Example:

```bash
curl --fail-with-body --silent --show-error \
  --request POST 'https://sso.user.m7.org/token/ack' \
  --header 'Content-Type: application/json' \
  --data '{
    "activation_id": "ACTIVATION_UUID",
    "activation_secret": "ACTIVATION_SECRET"
  }'
```

The activation secret itself authorizes acknowledgement for an unbound
lineage. Do not add a bearer access token to this request. Do not add
application-defined fields: M7 rejects any field other than the two fields
above.

A DPoP-bound pending lineage requires a fresh matching proof in the HTTP
`DPoP` header. Sign it with the bound key for exact HTU
`https://sso.user.m7.org/token/ack` and method `POST`; do not add it to the JSON
object. An unbound lineage does not require this header. See
[DPoP status](https://m7.org/docs/api/sso.user.m7.org/authorization.md#dpop-status).

## Success and commit sequence

M7 returns:

```json
{
  "token_state": "active",
  "activation_id": "ACTIVATION_UUID",
  "idempotent": false
}
```

Only after this response should your application atomically promote the new
package to active storage, delete `activation.secret`, and remove the stored
predecessor bundle. `idempotent: true` means the same activation had already
been completed successfully. If the first success response was lost, retry the
same activation credentials; a DPoP-bound client must create a fresh proof and
`jti`. A successful retry returns the same active result with `idempotent: true`
and does not perform a second transition.

## Failure and recovery

Handle ambiguous delivery according to which response was lost:

- If the refresh response containing `R1` is lost in `ack` mode, `R0` remains
  active, but another `R0` refresh receives `refresh_in_progress` while `R1`
  remains pending. Because the client does not have `R1`'s activation material,
  it must wait for expiry or operational resolution before refreshing again.
- If that refresh response is lost in `ack_supersede_pending` mode, the client
  may submit another valid refresh from retained active `R0`. M7 atomically
  revokes never-active `R1`, returns pending `R2`, and makes only `R2` eligible
  for ACK.
- If an ACK response times out or fails at the transport layer, retain the full
  pending envelope and predecessor bundle and retry the same activation. For a
  DPoP-bound lineage, use a completely new proof and `jti` from the same key.
  The ACK operation is idempotent if the earlier request already succeeded.

Do not interpret a proof or transport failure as permission to promote the
pending package locally.

Some lifecycle errors are terminal:

| Error | Meaning |
| --- | --- |
| `activation_expired` | The pending activation expired. Keep or restore the still-active predecessor and do not promote the expired package. |
| `activation_not_current` | A newer pending package superseded this one. Do not retry or promote the stale package; ACK only the latest retained package. |
| `activation_parent_not_current` or `activation_parent_invalid` | The package's predecessor is no longer the valid active parent. Do not promote or retry the stale activation. |
| `activation_not_pending` | This activation cannot make the package active. Do not retry or promote it. A previously successful activation instead returns the idempotent active response described above. |

## Security requirements

- Treat `activation_secret` as a bearer credential at least as sensitive as a
  refresh token.
- Do not write activation data to logs, browser storage, analytics, or support
  tickets.
- For a DPoP-bound lineage, never reuse a proof or `jti` for a later
  acknowledgement attempt.
- Preserve the predecessor until M7 confirms `token_state: "active"`.
- Never treat `ack_supersede_pending` as bypassing client authentication,
  refresh-package binding, activation-secret verification, or DPoP policy.
