# Authorization for `api.user.m7.org`

`api.user.m7.org` uses access tokens issued by M7 SSO, then applies its own
authorization checks for the current user, organization, or OAuth application.
An access token can additionally be sender-constrained to a DPoP key, a
fingerprint, or both. The required proof must accompany every request made
with that bound token.

The API base URL is:

```text
https://api.user.m7.org/api/v2
```

## Supported credentials

The [tenant member Security routes](https://m7.org/docs/api/api.user.m7.org/tenant-member-security.md) require a human
consumer principal with current active organization Management membership and
role `owner` or `admin`;
machine and tenant-member tokens are ineligible. Their independent route scopes
and mutation reasons supplement this credential policy. General organization
machine eligibility does not extend to those routes.

| Credential | Public transport | Where it applies | What the API validates |
| --- | --- | --- | --- |
| Consumer access token | `Authorization: Bearer <token>` | Consumer-owned resources and organization-management operations allowed by the endpoint | Token validity, live SSO session, current user and linked identity, expiry, ownership, and endpoint-specific permissions |
| Organization-member access token | `Authorization: Bearer <token>` | Endpoints that explicitly accept an organization member, including `/session/me` | Token validity, live member session, organization identity, expiry, and endpoint-specific permissions |
| Ordinary application access token | `Authorization: Bearer <token>` | Organization endpoints that explicitly allow machine applications | Token validity, live registration/directory binding, the app's own Management membership and stored role, and a live human manager |
| DPoP-bound access token | `Authorization: DPoP <token>` plus `DPoP: <proof>` | Every endpoint used with an access token whose `cnf.jkt` is present | ES256 proof signature, public JWK, exact method and canonical request URI, `ath`, bound-key match, freshness, and one-use `jti` |
| Fingerprint | `Fingerprint: <value>` | Required when the human access session was issued with a fingerprint binding | Exact continuity with the fingerprint recorded when the session was issued |

Refresh tokens, ID tokens, authorization codes, client secrets, and grant tokens
are not resource credentials. Do not send them to this API in place of an access
token.

API keys are also not management credentials for this API. Use an accepted SSO
access token to call `/api_keys/*`. A receiving service can validate a complete
API key through the separate
[SSO API-key verification endpoint](https://m7.org/docs/api/sso.user.m7.org/api-key-verification),
but that result does not authorize API User management operations.

## Obtain an access token

Use an M7 SSO flow appropriate to the caller:

- Interactive applications use the authorization-code flow with PKCE.
- Input-constrained applications can use the device authorization flow.
- Approved confidential applications can use the client-credentials flow for
  machine access.

See the [M7 SSO API documentation](https://m7.org/docs/api/sso.user.m7.org/)
for the authorization, token, device, refresh, and revocation endpoints. The
client secret authenticates a confidential client to the SSO token endpoint; it
never replaces a Bearer access token at `api.user.m7.org`.

Access tokens are signed JWTs, but clients should treat them as opaque. A decoded
claim is not proof that the token is current, accepted by this service, or
authorized for a resource.

## Audience, scopes and client identity

API.User requires an exact match to at least one accepted resource audience:
`https://user.m7.org` or `https://api.user.m7.org`. These values have no trailing
slash. A matching audience is necessary but does not replace endpoint scopes,
principal eligibility, account ownership, tenant permissions, current-state
checks or required sender bindings. It is not proof that an app owns a domain.

New M7 access tokens use issuer `https://sso.user.m7.org`; API.User also accepts
the explicit legacy issuer `id.m7.org` during migration. It does not trust an
arbitrary issuer or audience copied into a JWT.

`client_id` identifies the requesting OAuth app. The issuer-owned nested claim
`m7.target_client_id` identifies the receiving registered app; the issuer also
adds that UUID to `aud`. Ordinary app-bound issuance uses the same app for both
identifiers. Token Exchange can retain the source `client_id` while selecting a
different receiving app and recording the source as `act.sub`.

API.User does not impose a single mandatory `client_id` or target-app UUID on
all public callers. Other registered apps can use eligible user or machine
tokens with the required resource audience, scopes and endpoint authority.
Adding a UUID to `aud` does not grant permissions or change the target stamp.
See the [SSO token-claim contract](https://m7.org/docs/api/sso.user.m7.org/token-formats#requesting-client-and-receiving-application).

## Send a Bearer request

Send the access token in the `Authorization` header. For example:

```bash
curl --request POST \
  'https://api.user.m7.org/api/v2/session/me' \
  --header 'Authorization: Bearer ACCESS_TOKEN' \
  --header 'Content-Type: application/json' \
  --data '{}'
```

The Bearer scheme is case-insensitive. The public integration contract is the
`Authorization` header; do not put access tokens in URLs, query strings, or
cookies. Although older clients may use compatibility transports, new clients
must not depend on them.

Never log the complete header or token. Redact it as, for example,
`Authorization: Bearer eyJ…<redacted>`.

## DPoP-bound access tokens

When SSO returns `token_type=DPoP`, the client must retain the corresponding
private key and produce a fresh compact proof JWT for every API request. Send:

```http
Authorization: DPoP ACCESS_TOKEN
DPoP: DPOP_PROOF_JWT
```

Use an ES256 key. The proof header and payload should contain at least:

```json
{
  "typ": "dpop+jwt",
  "alg": "ES256",
  "jwk": {
    "kty": "EC",
    "crv": "P-256",
    "x": "PUBLIC_X",
    "y": "PUBLIC_Y"
  }
}
```

```json
{
  "jti": "UNIQUE_PROOF_ID",
  "htm": "POST",
  "htu": "https://api.user.m7.org/api/v2/session/me",
  "iat": 1787191200,
  "ath": "BASE64URL_SHA256_OF_ACCESS_TOKEN"
}
```

The private key must not appear in the JWK or leave the client. Use the exact
canonical absolute request URL without query or fragment for the proof's `htu`
claim, use the actual HTTP method for `htm`, set
`ath=base64url(SHA-256(ACCESS_TOKEN))`, generate a unique `jti`, and create a
new proof immediately before every request and retry. The public API derives
the request target itself; clients do not send an `HTU` header.

### Current validation profile

For a DPoP-bound access token, the resource validator enforces:

- an ES256 signature and `typ` of `dpop+jwt`;
- a public proof JWK whose thumbprint matches the access token's `cnf.jkt`;
- exact `htm` and canonical `htu` request binding;
- exact `ath` binding to the presented access token;
- an `iat` within the configured proof window; and
- atomic replay rejection for the key and one-use `jti`.

M7 currently does not issue a resource-server `DPoP-Nonce`. A rejected proof
returns HTTP 401 with a `WWW-Authenticate: DPoP` challenge and advertised
`algs="ES256"`; browser clients can read that header through CORS. An unbound
token must continue to use `Authorization: Bearer` and must not include a DPoP
proof. A DPoP-bound token presented as Bearer is rejected. A valid proof signed
by a key other than the token's `cnf.jkt` is an `invalid_token` binding failure;
malformed, stale, replayed, wrong-method, wrong-URI, or wrong-`ath` proofs are
`invalid_dpop_proof` failures.

## Fingerprint-bound sessions

A fingerprint is an opaque, caller-held continuity value. If it was supplied
when the human session was issued, send the exact original value on every API
request:

```http
Fingerprint: ORIGINAL_FINGERPRINT_VALUE
```

Current public issuance helpers use a cryptographically random 64-character
hexadecimal value. Generate it locally, do not derive it from easily observed
browser attributes, and store it with protection comparable to the access
token. The server stores a salted representation and compares the submitted
value without exposing the stored binding.

Losing or changing the original fingerprint invalidates use of that bound
session. Obtain a new session instead of attempting to reconstruct the value.

## Request with both bindings

A session may require both DPoP and a fingerprint:

```bash
curl --request POST \
  'https://api.user.m7.org/api/v2/session/me' \
  --header 'Authorization: DPoP ACCESS_TOKEN' \
  --header 'DPoP: DPOP_PROOF_JWT' \
  --header 'Fingerprint: ORIGINAL_FINGERPRINT_VALUE' \
  --header 'Content-Type: application/json' \
  --data '{}'
```

DPoP and fingerprint companion checks are independent. DPoP applies whenever
the access token contains `cnf.jkt`, including a DPoP-bound machine token;
principal, application, tenant, audience, scope, and current-state checks still
apply normally.

## Authorization after authentication

A valid token identifies a principal; it does not grant universal access.
Authorization is evaluated against current database state on each request.

### Consumer users

A consumer token can access the caller's own account resources. Personal OAuth
applications and personal API keys must be owned by the current user.
Organization operations, including organization API-key management, also
require the current user to hold active management access to that organization.
The local consumer `role` is not an access-token claim; `/session/me` returns
the current account role when the first-party UI needs to display it.

### Organization members

An organization-member token is accepted only by endpoints whose authentication
path explicitly supports that principal type. `/session/me` is one such
endpoint. Do not assume that possession of a member token alone grants access to
organization-management routes; follow each endpoint's documented principal
requirements.

### Organization machine applications

Machine access is opt-in per endpoint. For an ordinary client-credentials
application, the API requires all of the following:

- the token identifies an OAuth client rather than a human user or personal
  owner proxy;
- the registration is current, active and not archived; the token's identity
  directory matches the registration's stored tenant;
- the endpoint explicitly permits application credentials;
- the app itself has active Management membership and the required stored role
  in the organization named by the request; and
- that organization retains at least one active human Management member.

Personal registrations, organization consumer registrations and organization
tenant registrations can all use this ordinary application profile. The selected
organization can differ from the registration's owning `org` and identity
`tenant`; explicit Management membership authorizes it. Creator `uid`, app
ownership and token tenant claims do not supply membership or its role.

An organization machine application cannot create a new organization. Machine
tokens are also rejected from human-session endpoints such as `/session/me`.
Personal owner-proxy machine credentials are a separate restricted profile and
may be used only where an endpoint explicitly documents support.

### Roles, audience, and scopes

Organization ownership and Management-group roles are checked from current
service data. Owners control org properties, policy, lifecycle, identity
credentials, management access/scopes, client applications and API keys. Owners
and admins manage tenant accounts and ordinary tenant groups. Members can read
public org details and their own permission facts. Admin management-scope
delegation is deferred. See the [organization role matrix](https://m7.org/docs/api/api.user.m7.org/org.md#organization-roles).
Human admins/members may also [leave their own org](https://m7.org/docs/api/api.user.m7.org/org.md#leave-an-organization)
with explicit confirmation. Owners and machine callers cannot use self-departure.
The same role checks apply to eligible machine applications; token claims or
frontend visibility do not substitute for the current stored role.

Request the audience and scopes required by the issuing flow, but do not treat
decoded `aud` or `scope` claims as the complete authorization decision. Most
resource operations here additionally rely on current session status,
principal type, resource ownership, tenant equality, and Management-group
membership. An endpoint may impose still narrower checks.

## Consumer authenticator management

The [two-factor routes](https://m7.org/docs/api/api.user.m7.org/two-factor-authentication.md) require an authenticated
consumer account and operate only on that account's authenticator. They reject
machine and organization-member credentials and body-supplied principal
selectors. A successful access-token check does not replace the current TOTP,
recovery-code, or eligible linked-account proof required for a protected
settings change or unlink.

The account's password, email, Device Code, and existing-session two-factor settings
control hosted sign-in. They do not turn an ordinary API request or a refresh
request into an interactive TOTP prompt. Both magic-link and email-code
login use the ordinary SSO authorization-code flow. Neither an emailed proof
nor a completed email login replaces the proof required for authenticator
management. See the [email policy contract](https://m7.org/docs/api/api.user.m7.org/two-factor-authentication.md#email-sign-in-policy).

## Saved account consent

A consumer account manages its own [Authorized Apps](https://m7.org/docs/api/api.user.m7.org/authorized-apps.md) through
the authenticated `/account/me/authorized-apps/*` routes. Registration ownership,
organization membership, and a machine owner proxy cannot substitute for the
signed-in consumer. Consent-only withdrawal leaves issued tokens under their
normal lifetime rules. Optional grant-bound session revocation is a separate
operation with a stable request UUID and explicit pending/complete results;
it preserves the shared root login and other apps.

## Expiry, refresh, and revocation

The API revalidates a human access session against SSO and current local identity
state. A request fails when the session, user, linked identity, ancestor profile,
or relevant application is disabled, archived, revoked, expired, or otherwise
no longer valid.

- Use the access token's reported lifetime to refresh before expiry.
- Send refresh tokens only to the SSO token endpoint. Never send them to an API
  resource endpoint.
- A client-credentials access token has no human refresh session; request a new
  access token by authenticating the confidential client again.
- Revoke tokens through the SSO revocation flow, or through the applicable
  `api.user.m7.org` credential-management endpoint when the token was issued and
  recorded there.
- If a DPoP private key or bound fingerprint is lost, leaked, or rotated, revoke
  the affected session and authorize again with the new binding.

Do not keep retrying a rejected credential. Refresh or reauthorize once, then
surface the failure if the replacement is also rejected.

## API-key management boundary

API-key management routes authenticate the caller with an SSO access token,
derive the issuer from that authenticated principal, and enforce personal
ownership or current organization-management access. The `issued_for` and
`recipient_context` fields are attribution references; they do not switch the
principal or tenant.

The complete API key is returned once by creation or rotation. It is never a
replacement for the access token used to manage the record. Key-only SSO
verification consumes one use on success, enforces configured IP restrictions,
and can enforce supplied audience, scope, and expected-owner assertions. A
personal key's owner is its `uid`; an organization key's owner is its non-nil
`tenant` UUID. Consumer handles such as `root` resolve only personal owners,
while an owner array means any listed owner may match. The assertion does not
change ownership, select a management context, or reinterpret `issued_for`.
Verification returns updated usage and safe policy information for the
receiving service, but does not itself decide that service's full authorization.
See
[API key management](https://m7.org/docs/api/api.user.m7.org/api-keys.md) for the route and lifecycle contract.

## Connection-verification exception

`POST /oauth/clients/connections/verify` is a verification helper, not a normal
resource endpoint. It intentionally does not authenticate the caller with a
Bearer header. Instead, it accepts the token to inspect and the provider client
identifier in the JSON body:

```bash
curl --request POST \
  'https://api.user.m7.org/api/v2/oauth/clients/connections/verify' \
  --header 'Content-Type: application/json' \
  --data '{
    "token": "ACCESS_TOKEN_TO_VERIFY",
    "provider_client_id": "PROVIDER_CLIENT_ID"
  }'
```

The helper verifies the token cryptographically and evaluates the current
provider, consumer, audience, connection, and approved-scope relationship. Its
result applies only to that connection check. Do not generalize it into
authorization for another endpoint. DPoP and fingerprint companion headers are
not part of this verification helper.

## Common failures

API responses use the service response envelope; unsuccessful authorization is
reported with failure status and a diagnostic comment. Treat comments as
diagnostics rather than a stable machine protocol.

| Failure | Typical cause | Client action |
| --- | --- | --- |
| Missing credentials | No accepted access token was supplied | Add the Bearer header; do not substitute a refresh or ID token |
| Failed to validate token / invalid JWT | Bad signature, issuer certificate, token shape, or upstream validation | Discard the token and obtain a new one from SSO |
| Session is expired or revoked | The SSO session is no longer active | Refresh if the flow permits it; otherwise authorize again |
| DPoP required / DPoP invalid | A bound token omitted the proof, used the wrong key, method, URL, token hash, algorithm, time, or repeated `jti` | Generate a fresh proof with the bound key and exact `htm`, `htu`, and `ath` |
| DPoP JWK thumbprint mismatch | The proof key is not the key bound to the session | Use the original private key or establish a new session |
| Fingerprint invalid | The exact session fingerprint was omitted or changed | Send the original value or establish a new session |
| User or linked identity unavailable | The local account mapping is absent, disabled, or expired | Reauthenticate; if persistent, repair the account rather than retrying |
| OAuth client inactive or tenant mismatch | The app is disabled/archived, or its token directory differs from the live registration's tenant | Use an active registration and correctly bound token; target-org access separately requires live Management membership |
| Machine access not allowed | The endpoint does not opt into the machine principal | Use a supported human principal or an endpoint that documents machine access |
| Organization management access denied | Current Management-group or live-human-management requirements are not met | Restore approved management access; do not attempt to bypass the check |

## Security checklist

- Keep access tokens, refresh tokens, client secrets, DPoP private keys, and
  fingerprints out of source control, URLs, analytics, and logs.
- Use TLS and the exact `https://api.user.m7.org` host in production.
- Prefer short-lived access tokens and minimum required scopes.
- Validate authorization from API results, not locally decoded token claims.
- Maintain clock synchronization for fresh DPoP proofs.
- Rotate and revoke credentials after suspected disclosure.
- Consult the endpoint documentation for its accepted principal and resource
  checks before enabling a machine integration.

Related documentation:

- [M7 SSO API](https://m7.org/docs/api/sso.user.m7.org/)
- [`api.user.m7.org` API](https://m7.org/docs/api/api.user.m7.org/)
