# Authorization for `api.blog.service.m7.org`

The M7 Blog Service uses M7 access tokens for protected management requests.
After validating a token, the service uses its current trusted M7Roster
principal projection and applies admission, workspace, publication membership,
and capability rules. Machine callers also require receiver-authenticated ACL
introspection for this API.
Public read requests do not require a credential.

The API base URL is:

```text
https://api.blog.service.m7.org/v1
```

## Supported credential

| Credential | Format | Public transport | Where it applies |
| --- | --- | --- | --- |
| M7 access token | Signed compact JWT; clients must treat it as opaque | `Authorization: Bearer ACCESS_TOKEN` | Protected publication-management routes under `/v1` |

The same access-token format is used for user-authorized and confidential
machine callers. The token's resolved principal and the selected publication
determine what the caller may do.

ID tokens, refresh tokens, authorization codes, device codes, client secrets,
and DPoP proofs do not replace an access token on Blog Service routes. Send
those credentials only to the M7 SSO endpoint or flow that defines them.

## Obtain an access token

The Blog Service does not issue, refresh, or revoke M7 credentials. Discover
the current authorization endpoints at:

```text
GET https://sso.user.m7.org/.well-known/openid-configuration
```

Use the [M7 SSO API](https://m7.org/docs/api/sso.user.m7.org/) flow that
matches the caller:

| Caller | Flow |
| --- | --- |
| Browser, native application, or server-rendered application acting for a user | Authorization code with PKCE |
| CLI, TV, or other input-constrained application acting for a user | Device authorization |
| Confidential service acting as itself | `client_credentials` |

Token exchanges use:

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

Authenticate the OAuth client using its configured token-endpoint method.
Public clients may use `none` with a body `client_id`; confidential clients
may use methods such as `client_secret_basic`, `client_secret_post`,
`client_secret_jwt`, or `private_key_jwt`. Never embed a confidential client
credential in browser, native, CLI, or device code.

User-authorized flows may return a refresh package. Send the `refresh_token`,
`binding_chain`, `binding_link`, and any required fingerprint only to the M7
SSO token endpoint. A `client_credentials` token has no refresh token; obtain
a replacement by authenticating the confidential client again.

## Send an authenticated request

Use the `Bearer` scheme, one space, and the access token:

```bash
curl --fail-with-body --silent --show-error \
  --request POST 'https://api.blog.service.m7.org/v1/publication/list' \
  --header 'Authorization: Bearer ACCESS_TOKEN' \
  --header 'Content-Type: application/json' \
  --data '{}'
```

Do not put an access token in a URL, query string, request body, or cookie. Do
not rely on compatibility token headers. Never log the complete token or
`Authorization` header.

M7 access tokens are JWTs, but decoded claims are not proof that a token is
valid or that the caller is authorized for a publication. Use the API response
as the authorization decision.

The service currently validates:

- compact JWT structure and signature;
- the `RS512` signing algorithm;
- either accepted issuer, `https://sso.user.m7.org` or `id.m7.org`;
- an HTTPS signing-certificate source hosted by `sso.user.m7.org` or `id.m7.org`;
- the exact audience `https://api.blog.service.m7.org`; and
- `nbf`, `iat`, and `exp` time claims when present.

Every protected route requires the Blog API audience. The production-import
route applies its additional, narrower audience check as described below.

Publication and content capabilities do not come from an OAuth `scope` claim.
Organization-backed creation additionally requires the explicitly requested
`orgs` scope for its live SSO lookup.

## Principals and publication boundaries

Admission requires the current trusted principal projection to be active
with the exact service-list role `member`, `user`, `admin`, or `root`. A local
roster reference is not a grant for later requests. Machine tokens additionally
require current receiver-authenticated ACL admission. A token's broad role claim
does not override this service-list projection.

Workspace selection then determines the effective principal. See
[identity and organization workspaces](https://m7.org/docs/api/api.blog.service.m7.org/workspaces.md). Authorization follows
that principal's publication membership:

| Principal | Publication boundary |
| --- | --- |
| User or delegate principal | Requires its own active publication membership; current role defaults or selected member capabilities and lifecycle rules bound its actions. An owner link does not substitute for membership. |
| Effective organization principal | Requires the org's own active publication membership. Resolved direct Management tag-name grants are intersected with that publication's permissions. The real actor's personal membership is not inherited. |
| Service `admin`, `root`, application, or internal principal | Service-wide status does not assign publication membership or bypass the publication workspace boundary. |

A user or delegate does not gain access by knowing a publication slug, a
publication UUID, or a resource UUID. The selected publication must be active
unless the requested lifecycle action explicitly supports archived
publications.

### Publication membership roles

Only an active membership is used. Invited, disabled, and removed memberships
do not authorize a request.

| Membership role | Current capability boundary |
| --- | --- |
| `owner` | Current publication role defaults or explicitly selected optional capabilities within the Owner limit, plus intrinsic membership actions; final-owner protections still apply. |
| `admin` | Current publication role defaults or explicitly selected optional capabilities within the Admin limit; Owner-only role-assignment protections remain independent. |
| `member` | Current publication role defaults or explicitly selected optional capabilities within the Member limit; broadened presets do not create Owner/Admin membership authority. |

Each protected operation also checks its named publication capability. A valid
token and active membership can therefore still receive HTTP `403` when the
membership role does not include that action.

### Organization Management tag profiles

Blog consumes current direct Management tags returned by
recipient-authenticated SSO. Each tag's **`name`** is the
capability/profile identifier. SSO preserves dots and case; slug normalization
is separate. For example (other response fields omitted):

```json
{"name": "test.me", "slug": "testme", "data": null}
```

Names can identify primitives, families, or presets, such as `post.save`,
`post.read`, or `preset.writer`. Resolution is case-insensitive through the
current capability catalogue. Unknown names are discarded. A nonempty tag
list containing only unknown names grants nothing and never triggers defaults.
The resolver reads `name` only; slugs and arbitrary tag `data` do not supply
capability grants. Slugs may still serve generic tag purposes. No capability
list in tag data is required.

Only a verified empty tag list permits the Owner/Admin role mappings
(`role.owner` / `role.admin` in the baseline). Member receives no automatic org
capabilities. Missing/malformed Management facts, tag lists, or names fail
closed. Lookup or catalogue failure cannot supply an empty-selection fallback.
Returned facts must be current direct membership data disclosed to Blog's
receiving registration; cached org lists and roster references are not grants.

Resolved org actions are intersected with the org's actual publication
permissions, including publication defaults or selected member actions
and lifecycle restrictions. Membership, ownership, owner-controlled disclosure,
membership-management, and final-owner checks remain independent. The real
actor is preserved separately from the effective org principal. A selected
Owner pack does not make the caller an Owner or confer personal resource access.

Grants use the current capability definitions. A read-only selection is
additive to separately selected writes: selecting both does not revoke the
writes. A profile permitting `post.save` can modify published posts; clients
must not interpret that grant as draft-only editing.

### Publication creation

`POST /v1/publication/create` accepts active admitted user or organization
workspaces with `publication.create`. In Personal, the user's stable principal
becomes the Management owner; in an organization workspace, the verified org
principal becomes the owner and the real actor remains separately attributed.
Caller-supplied owner, principal, creator and member overrides
are rejected.

An ordinary machine must select an organization using native `org_id` or the
`Org` header, and explicitly request the `orgs` scope when obtaining its token. Blog authenticates itself as the receiving
service for a fresh SSO `/introspect/orgs` lookup. The selected organization must
have a current Management membership for that machine and permit disclosure to
Blog's registration. All three current Management roles (`owner`, `admin`, and
`member`) qualify for its membership gate; the resolved org profile must also
grant `publication.create`. A verified empty Member tag list grants no creation
capability. Cached names, cached lists, inbound org
objects and stored roster references do not authorize creation.

```json
{"name": "Agent notes", "slug": "agent-notes", "org_id": "ORGANIZATION_UUID"}
```

On success, the organization's returned stable `principal_id` becomes the pinned
Management owner; `created_by` remains the machine's principal. The org roster
reference and publication writes share the creation transaction. The response's
`ownership` object identifies the owner principal, kind and native org ID.
A user may also select an organization through the same verified workspace
contract. Omitting selection keeps user or owner-proxy creation personal.

Missing or unauthorized organizations and missing `orgs` scope deny machine
creation with HTTP `403`; malformed `org_id` returns HTTP `400`. Upstream lookup
failures fail closed. This gate also applies to the shared publication-creation
service; the separate production-import profile remains owner-proxy only.

## Confidential machine callers

Use `client_credentials` only for a registered confidential application acting
as itself. Authenticate the client at the M7 SSO token endpoint using its
configured method and request the audience assigned to the integration. The
returned application-principal access token is sent to this API with the same
`Authorization: Bearer ACCESS_TOKEN` contract.

Machine identity does not supply another principal's publication membership.
Publication workspace operations require the effective principal's actual
membership; org workspaces also apply the verified Management tag profile and
publication permission intersection described above. Keep client credentials
in a server-side secret store. A validated machine-owner proxy resolves to its
owner user principal and remains subject to that principal's publication access.

### Production import profile

`POST /v1/import/production` has additional checks for the trusted source
machine. Its access token must:

- resolve from the deployment's configured source-machine client ID;
- contain the same `client_id` as that configured source machine;
- identify `principal_type` as `oauth_client`;
- contain `machine_owner_proxy: true`; and
- contain the issuer-managed owner-principal binding required by that proxy
  profile; and
- contain the general Blog API audience `https://api.blog.service.m7.org` in
  `aud`; and
- contain the deployment's exact production-import audience in `aud`.

The default production-import audience is:

```text
https://api.blog.service.m7.org/v1/
```

A deployment can configure another exact production-import audience. The token
must contain both the general Blog API audience and that production-import
audience. The OAuth client must be
provisioned so its issued token contains the required machine-owner profile;
client input alone cannot grant that trust. The production bundle's
`source.machine_id` must also match the verified token `client_id`.

For an existing target publication, the resolved proxy principal must have an
active membership whose capabilities include `import.production`. For a new
target, the proxy principal must be allowed to create a publication and
becomes the new publication's owner.

For example, a client configured for `client_secret_basic` obtains an access
token with the deployment's assigned audience:

```bash
curl --fail-with-body --silent --show-error \
  --request POST 'https://sso.user.m7.org/token' \
  --user 'CLIENT_ID:CLIENT_SECRET' \
  --data-urlencode 'grant_type=client_credentials' \
  --data-urlencode 'aud[]=https://api.blog.service.m7.org' \
  --data-urlencode 'aud[]=https://api.blog.service.m7.org/v1/' \
  --data-urlencode 'access_expires=900'
```

This example does not itself create the required machine-owner trust. Use only
the registered source-machine client selected by the deployment.

## DPoP status

DPoP is not part of the supported Blog Service authorization contract. The
service validates the Bearer access token but does not validate a DPoP proof's
signature, HTTP method and URL binding, access-token binding, freshness,
unique identifier, or replay state. CORS allowance and parsing of `DPoP`,
`HTU`, or related headers do not provide end-to-end enforcement.

If an existing SSO credential lineage requires DPoP while acquiring or
refreshing a credential, follow that SSO compatibility contract. Do not rely
on a DPoP proof to authorize or protect a Blog Service resource request.

## Expiry, refresh, and revocation

- Stop using an access token when its issuer-reported lifetime ends. This API
  does not extend token lifetimes.
- Refresh a user-authorized package only at `POST
  https://sso.user.m7.org/token`, using the complete package and the OAuth
  client's required authentication.
- Reissue a `client_credentials` token through the same SSO token endpoint; it
  has no refresh package.
- Revoke an eligible credential through `POST
  https://sso.user.m7.org/revoke` and discard every local copy. The Blog
  Service has no local token-revocation endpoint.
- The Blog Service validates access-token JWTs locally. User token revocation
  is not introspected on every request, so a revoked user token can remain
  accepted until its signed validity period ends. Machine receiver-ACL admission
  is separately checked using its configured short cache.
- Changing current service-list admission or disabling publication membership can deny later
  requests independently of token expiry.

After a terminal refresh or revocation error, discard the unusable credential
package and begin a new supported authorization flow instead of retrying it
indefinitely.

## Authentication and authorization failures

Admission failures use HTTP `401` for absent or invalid tokens, `503` when
receiver ACL configuration or lookup is unavailable, and `403` for other
admission denials:

```json
{
  "status": 0,
  "comment": "Access denied",
  "data": {
    "code": 401,
    "reason": "missing_token",
    "boundary": "roster",
    "stage": "stage-2-mvp-0"
  }
}
```

Publication membership and capability failures also use the service's normal
error envelope. Inspect the HTTP status, `status`, and `data.code`; do not
branch only on the human-readable `comment`.

| Failure | Typical cause | Client action |
| --- | --- | --- |
| HTTP `401`, `missing_token` or `invalid_token` | Bearer header is absent, token validation failed, or claims could not resolve a principal | Send a valid M7 access token; if one was already sent, discard it and obtain a replacement from SSO. |
| HTTP `403`, principal access denial | The current trusted projection is inactive or its service-list role is not allowed | Restore the principal's access or use another authorized principal. |
| HTTP `403`, publication access denial | The user or delegate lacks an active membership in the selected publication | Use a member principal or request access through the publication owner. |
| HTTP `403`, capability access denial | The membership role does not grant the requested operation | Use an allowed operation or a membership role with that capability. |
| HTTP `503`, receiver ACL unavailable | Receiver authentication is unconfigured or the live ACL lookup failed | Retry after receiver authorization is restored; never fall back to stored roster access. |
| HTTP `403`, `production import access denied` | The source-machine client, machine-owner marker, or exact audience does not match | Stop and correct the registered machine-client configuration; do not retry with caller-supplied identity claims. |

## Security checklist

- Use TLS and the exact `https://api.blog.service.m7.org/v1` production base
  URL.
- Keep access tokens, refresh packages, client secrets, authorization codes,
  device codes, fingerprints, and DPoP private keys out of source control,
  logs, analytics, URLs, and error reports.
- Store long-lived refresh material and confidential-client credentials in an
  application-owned secure store.
- Request only the grants, audience, scopes, and lifetime required by the
  integration.
- Revoke and replace credentials after suspected disclosure.
- Treat publication and content identifiers as references, not credentials;
  the service still applies principal and publication authorization.
- Use current API responses and server-managed membership state for access
  decisions. Do not authorize from decoded JWT claims in client code.

Related documentation:

- [M7 SSO API](https://m7.org/docs/api/sso.user.m7.org/)
- [M7 Blog Service API](https://m7.org/docs/api/api.blog.service.m7.org/)
