Skip to content

Mint audience-bound service tokens from application grants #876

Open

Description

@NateIsern

Reconciliation — 2026-10-05

This is completion of reusable Oxy-audience foundations, not acceptance of resource-targeted Mercaria→Moovo minting. The requested resource API/grant intersection, per-resource cache isolation and generic audience migration below remain open. No checkbox for that different flow is inferred from aud: oxy-api.


Status 2026-09-30 (audited against main f345d27)
Still to do: serviceTokenMint.service.ts:54 hardcodes aud: 'oxy-api' for BOTH the key/secret mint and the workload mint (/auth/service-token/workload, ADR 0026) — cover both. Payments carve-out still at routes/auth.ts:3682. No compatibility route for oxy-api tokens: clean cut.


Part of #873. Depends on #874 and #875.

Goal

Extend Oxy service-token issuance so a service credential can request a short-lived token for one registered resource application and a bounded service-scope subset. The mint must derive every identity and permission from Oxy records and must not trust caller-supplied application ids as authority.

Token request

Evolve the existing service-token flow according to #874, using standard OAuth parameters where practical. The request must identify:

  1. Existing service credential client id and secret.
  2. Target resource application or audience.
  3. Requested service scopes.
  4. No caller application id; it is resolved from the credential.
  5. No user id unless a separate explicit delegation flow is being used.

Preserve a compatibility route or versioned migration for current oxy-api service tokens without making an unscoped token valid against every application resource.

Authorization sequence

  1. Resolve the usable ApplicationCredential by client id.
  2. Verify the secret with the existing constant-time/hash path.
  3. Resolve the owning caller Application and require active status.
  4. Resolve the requested resource Application and require active status.
  5. Require environment compatibility.
  6. Resolve the active application service grant from Model resource service APIs and application-to-application grants #875.
  7. Intersect requested scopes with the resource API definition, grant and credential binding.
  8. Reject unknown, retired, ungranted or cross-environment scopes.
  9. Mint a short-lived token with the exact caller, credential, resource, environment and effective scopes.
  10. Stamp safe last-used and audit information without logging secrets or raw tokens.

Token contract

Implement the claim shape selected by #874, including:

  1. type: service.
  2. Caller appId.
  3. credentialId.
  4. Resource application audience.
  5. Environment.
  6. Effective service scopes.
  7. iss, iat, exp and key id as applicable.
  8. A token/version marker if required for safe migration.

Do not use application display name, domain or official badge as authority.

Cache and revocation behavior

  1. Cache keys include credential, audience, environment and normalized scope set.
  2. A token for Moovo cannot be returned for Oxy API or another application.
  3. Credential rotation does not mix token caches.
  4. Grant revocation prevents minting a replacement token immediately.
  5. Already issued token behavior follows ADR: define canonical application principals, resource audiences and service grants #874's bounded lifetime/revocation decision.
  6. Resource or caller suspension prevents minting.
  7. Scope reductions cannot be widened by an empty requested scope fallback.
  8. Concurrent equivalent requests may converge safely without sharing tokens across credential tuples.

Error contract

Use safe OAuth-style errors or the accepted service-token contract for:

  1. Invalid client.
  2. Invalid resource.
  3. Invalid or unavailable scope.
  4. Environment mismatch.
  5. Missing/revoked/suspended grant.
  6. Suspended application.
  7. Revoked or expired credential.
  8. Unsupported compatibility request.

Do not reveal whether an unrelated application has a private grant.

Tests

Use real persistence and cover:

  1. Mercaria production credential to Moovo production.
  2. Wrong resource.
  3. No grant.
  4. Scope outside grant.
  5. Scope outside credential binding.
  6. Development credential to production resource.
  7. Grant revoked during token refresh.
  8. Credential rotation grace and final revocation.
  9. Resource suspended.
  10. Token cache isolation by audience and scopes.
  11. Current Oxy API compatibility path.
  12. Request body trying to spoof caller application id.
  13. Empty-scope and unknown-scope behavior.
  14. Audit and last-used fields.

Acceptance criteria

  1. Mercaria can mint a token whose audience is the existing Moovo application id.
  2. The token contains only the exact effective scopes permitted by Model resource service APIs and application-to-application grants #875.
  3. A token for one resource cannot be replayed as a token for another resource.
  4. Caller identity comes only from the resolved credential.
  5. Environment and lifecycle checks fail closed.
  6. Current service-token consumers have a tested migration path.
  7. No local or shared SERVICE_SECRET is required by this flow.
  8. Documentation and SDK contracts can rely on one authoritative token mint.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions