Engineering guide · ICAM

OAuth Grants, Refresh Tokens, And Token Exchange

Status: implemented; focused tests pass, Docker runtime execution deferred while host capacity is constrainedReviewed: 2026-07-25Audience: OAuth client developers, AI-agent developers, resource-server engineers, security reviewers
On this pageUser-Centric Grant APIRefresh-Token ProtocolUser-Centric Refresh-Token APIToken-Exchange ConnectionStage One: ID Token To ID-JAGStage Two: ID-JAG To Resource Access TokenService And Agent Access Tokens As Subject TokensFailure And Evidence SemanticsVerification

Atlas exposes an Okta-friendly user OAuth management surface and a policy-constrained token-exchange broker. The implementation uses one API-access authority for clients, grants, refresh families, exchange connections, replay state, and evidence. The OIDC service retains signing-key authority and never becomes a second management database.

The relevant standards and compatibility baselines are RFC 8693 OAuth Token Exchange, RFC 7009 Token Revocation, and the Okta User OAuth Token API. ID-JAG is an Atlas-supported requested token type for two-stage human, service, and agent-to-agent delegation.

User-Centric Grant API

Operation Purpose Capability Assurance

GET /api/v1/users/{userId}/grants

List durable OAuth grants for the user.

users.oauth.grants.read

AAL1

GET /api/v1/users/{userId}/grants/{grantId}

Read a grant only when its subject matches the path user.

users.oauth.grants.read

AAL1

DELETE /api/v1/users/{userId}/grants/{grantId}

Atomically revoke the grant and immediately invalidate every Atlas access token carrying its grant_id.

users.oauth.grants.revoke

fresh AAL2

Revocation accepts an optional reason query parameter or X-Atlas-Reason header. Atlas records a safe default when neither is supplied, preserving the one-request Okta-compatible operation while retaining evidence. The service verifies the user binding before mutation and uses the current grant evidence hash in its compare-and-swap.

Refresh-Token Protocol

Register the client for authorization_code, refresh_token, and offline_access. Request offline_access at authorization time. The authorization-code response then includes one raw refresh token:

{
  "access_token": "eyJ...",
  "id_token": "eyJ...",
  "refresh_token": "atrf_...",
  "token_type": "Bearer",
  "expires_in": 900,
  "scope": "offline_access openid profile"
}

Exchange it with HTTP Basic client authentication:

curl --fail-with-body \
  --user "${CLIENT_ID}:${CLIENT_SECRET}" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -X POST "https://id.atlas.example/oauth2/${TENANT_ID}/v1/token" \
  --data-urlencode "grant_type=refresh_token" \
  --data-urlencode "refresh_token=${REFRESH_TOKEN}"

Every successful exchange returns a different refresh token. Clients must replace the old value atomically. Atlas deliberately rejects scope expansion and currently requires an omitted scope or the exact original scope set.

The API-access service persists a single compare-and-swap aggregate for the entire family. It contains random token identifiers, SHA-256 token digests, status, grant bindings, bounded history, expiry, and evidence. It never contains the raw atrf_…​ value. The family prefix identifies the record without making the random 256-bit secret searchable. Digest comparison is constant-time.

Presenting a rotated token changes the family to reuse_detected, revokes its current durable grant, and makes both the new refresh token and already-issued grant-bound access token unusable. Concurrent refresh requests therefore produce at most one usable result. An access-token verifier also resolves refresh-family state for associated grants, so a failed follow-on audit call cannot reopen a revoked family.

User-Centric Refresh-Token API

Operation Purpose

GET /api/v1/users/{userId}/clients/{clientId}/tokens

List refresh-token metadata for a user/client pair.

GET /api/v1/users/{userId}/clients/{clientId}/tokens/{tokenId}

Read one metadata record.

DELETE /api/v1/users/{userId}/clients/{clientId}/tokens/{tokenId}

Revoke the token’s complete rotation family and current access grant.

DELETE /api/v1/users/{userId}/clients/{clientId}/tokens

Revoke every active family for the user/client pair.

Reads require users.oauth.tokens.read. Revocations require users.oauth.tokens.revoke and fresh AAL2. Delete is idempotent and non-enumerating: an unknown or already-revoked token identifier still returns 204. Management responses contain metadata only; no route can recover a refresh credential or its stored digest.

Token-Exchange Connection

An exchange is impossible until an independently approved connection binds all of the following:

  • the first-class active AI workload principal;

  • the active delegation link that authorizes the subject client and scopes;

  • the agent client that may request delegation;

  • the distinct origin client that received the human ID token or obtained the service access token, or the distinct source-agent client for a later hop;

  • the distinct resource client that may consume the ID-JAG;

  • an active MCP/API resource-server aggregate and one ready authorization binding;

  • one exact audience;

  • an allowlist of scopes;

  • an ID-JAG lifetime from 30 through 300 seconds.

Create a pending connection:

curl --fail-with-body \
  -H "Authorization: Bearer ${AAL2_OPERATOR_TOKEN}" \
  -H "Content-Type: application/json" \
  -X POST https://id.atlas.example/api/v1/oauth2/token-exchange/connections \
  --data '{
    "name": "mission-agent to logistics API",
    "agentId": "agent_...",
    "delegationLinkId": "delegation_...",
    "resourceServerId": "resource_server_...",
    "resourceAuthorizationServerId": "resource_authorization_server_...",
    "agentClientId": "mission-agent",
    "subjectClientId": "mission-portal",
    "resourceClientId": "logistics-api",
    "audience": "https://logistics.example.mil",
    "allowedScopes": ["profile", "read:users"],
    "idJagTtlSeconds": 300
  }'

For the Okta-friendly first-class workload surface, create the same authoritative connection beneath /workload-principals/api/v1/ai-agents/{agentId}/connections; the path supplies and enforces agentId. See AI Workload Principals And Delegation for agent, public-JWK, private_key_jwt, and delegation-link registration. See MCP And API Resource Servers for protected resource registration, hardened metadata readiness, capability inventory, and potential-connection discovery.

All three clients must already be enabled, approved, mutually distinct, and registered for their protocol role: token exchange for the receiving agent; authorization code for a human-origin subject, client credentials for a service origin, or token exchange for a source agent; and token exchange or JWT bearer for the downstream resource. The resource server must be independently active, its resource URI must equal the connection audience, its scopes must contain the connection allowlist, and the selected Atlas XAA authorization binding must be ready, unexpired, and bound to that resource client. When the delegation accepts an access-token subject, the connection must also set inboundResourceServerId to the exact active resource registration at which the receiving agent accepts the subject token. That inbound aggregate and readiness epoch are persisted in the one-time ID-JAG evidence and rechecked at consumption. Activate using the returned evidence hash and a different actor with fresh AAL3:

curl --fail-with-body \
  -H "Authorization: Bearer ${INDEPENDENT_AAL3_TOKEN}" \
  -H 'If-Match: "CURRENT_EVIDENCE_SHA256"' \
  -H "Content-Type: application/json" \
  -X POST \
  "https://id.atlas.example/api/v1/oauth2/token-exchange/connections/${CONNECTION_ID}/activate" \
  --data '{"reason":"independent audience and least-privilege review completed"}'

Connection reads use oauth2.token-exchange.read. Creation uses oauth2.token-exchange.manage. Activation and revocation use oauth2.token-exchange.approve, fresh AAL3, independent activation, and If-Match. The API-access authority independently rejects future-dated authentication and rechecks all three client states, resource readiness, exact binding, and grant types at activation and use. Revoking the connection prevents both issuance and consumption.

Stage One: ID Token To ID-JAG

The agent authenticates as its approved confidential client and sends the human subject’s Atlas ID token:

An active first-class AI workload should authenticate without a reusable client secret by replacing HTTP Basic with:

client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer
client_assertion=<ES384-or-RS256-signed-one-time-assertion>

The assertion’s iss and sub equal the agent client identifier, aud equals this exact token endpoint, lifetime is at most five minutes, and jti is consumed atomically once.

curl --fail-with-body \
  --user "mission-agent:${AGENT_CLIENT_SECRET}" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -X POST "https://id.atlas.example/oauth2/${TENANT_ID}/v1/token" \
  --data-urlencode \
    "grant_type=urn:ietf:params:oauth:grant-type:token-exchange" \
  --data-urlencode "subject_token=${SUBJECT_ID_TOKEN}" \
  --data-urlencode \
    "subject_token_type=urn:ietf:params:oauth:token-type:id_token" \
  --data-urlencode \
    "requested_token_type=urn:ietf:params:oauth:token-type:id-jag" \
  --data-urlencode "audience=https://logistics.example.mil" \
  --data-urlencode "scope=profile read:users"

Atlas verifies the ID token with the tenant’s current or overlap ES384 key, exact issuer and tenant, bounded lifetime, subject client, audience, and JTI. It then resolves one active connection matching the authenticated agent, subject client, exact audience, and requested scope subset. The connection’s agent, delegation, three clients, resource server, authorization binding, exact resource URI, and readiness expiry are rechecked before issuance.

The response uses the RFC 8693 fields:

{
  "access_token": "eyJ...",
  "issued_token_type": "urn:ietf:params:oauth:token-type:id-jag",
  "token_type": "N_A",
  "expires_in": 300,
  "scope": "profile read:users"
}

The ES384 ID-JAG has typ: id-jag+jwt. It binds the human subject and sub_profile, authorization-server audience, exact resource, authenticated agent in the RFC 8693 nested act claim, connection identifier, original subject-token JTI, new random JTI, tenant, scopes, issue time, and expiry. Before returning it, Atlas atomically registers the JTI and complete token digest as unconsumed evidence. The registry independently rejects an expiry beyond the connection’s configured 30-to-300-second lifetime, so a compromised or defective caller cannot widen the delegation window.

Stage Two: ID-JAG To Resource Access Token

The approved resource client consumes the ID-JAG:

curl --fail-with-body \
  --user "logistics-api:${RESOURCE_CLIENT_SECRET}" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -X POST "https://id.atlas.example/oauth2/${TENANT_ID}/v1/token" \
  --data-urlencode \
    "grant_type=urn:ietf:params:oauth:grant-type:token-exchange" \
  --data-urlencode "subject_token=${ID_JAG}" \
  --data-urlencode \
    "subject_token_type=urn:ietf:params:oauth:token-type:id-jag" \
  --data-urlencode \
    "requested_token_type=urn:ietf:params:oauth:token-type:access_token" \
  --data-urlencode "audience=https://logistics.example.mil" \
  --data-urlencode "scope=profile read:users"

grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer with the ID-JAG in assertion is also supported for the second stage.

Atlas verifies the signature, type, issuer, tenant, lifetime, audience, scope, resource client, connection state, JTI, and complete token digest. It again rechecks first-class resource readiness before the one-time consume, so deactivation, metadata invalidation, or readiness expiry between stages fails closed. The registration record binds the connection, resource, and authorization evidence hashes. Any intervening lifecycle or metadata-validation revision invalidates the ID-JAG permanently; reactivation does not resurrect an older delegation epoch. The atomic consume occurs once across replicas. Atlas then obtains a new durable grant for the resource client and signs a short-lived at+jwt containing the human subject, resource audience, grant_id, connection identifier, and original agent in act. Replay returns invalid_grant. An unknown, mismatched, or overbroad resource returns invalid_target or invalid_scope without revealing connection inventory.

Atlas issues short-lived resource access tokens. It does not return a vaulted password, API key, service-account secret, or downstream provider refresh token. Where an external provider owns the final token, a deployment adapter must perform that provider exchange and retain the provider’s revocation semantics; Atlas does not claim authority over that downstream token.

Service And Agent Access Tokens As Subject Tokens

Atlas also accepts subject_token_type=urn:ietf:params:oauth:token-type:access_token when the high-assurance workload authority is configured. There is no permissive legacy fallback for this form.

For a service origin, obtain the subject token with client_credentials and an exact resource parameter naming the first agent. For a later agent hop, use the previous resource access token. In either case the receiving agent requests a new ID-JAG with:

grant_type=urn:ietf:params:oauth:grant-type:token-exchange
subject_token=<RESOURCE_BOUND_ACCESS_TOKEN>
subject_token_type=urn:ietf:params:oauth:token-type:access_token
requested_token_type=urn:ietf:params:oauth:token-type:id-jag
audience=<ATLAS_TENANT_ISSUER>
resource=<EXACT_NEXT_AGENT_OR_API_RESOURCE_URI>
scope=<EXACT_ALLOWED_SCOPE_SET>

Atlas validates the subject access token’s signature, issuer, tenant, lifetime, durable grant_id, resource, audience, profile, JTI, and nested actor chain. The incoming resource must be an active, readiness-current API registration bound to the receiving agent’s OAuth client. The immediate incoming actor must match the active delegation link’s source agent; a service-origin token without an actor chain instead matches the active OAUTH_CLIENT link. The authenticated receiving agent is prepended, not substituted.

Actor chains contain no more than five unique subjects and are ordered from the immediate caller to the origin. The final origin may be a service; preceding entries are ai_agent. Cycle, depth, source, target, lifecycle, and scope failures are fail-closed. See AI Workload Principals And Delegation for the complete two-agent example and management graph.

Failure And Evidence Semantics

Error Meaning

invalid_client

Client identity or Vault-resolved secret failed without identifier enumeration.

invalid_grant

Code, refresh token, subject token, ID-JAG, durable grant, JTI, or replay state failed.

invalid_scope

Requested scopes are unknown, duplicated, expanded, or outside the connection allowlist.

invalid_target

Audience, resource, subject client, agent client, or resource client does not match one active connection.

slow_down

The authenticated client or tenant exceeded its request or concurrency budget.

Protocol responses are Cache-Control: no-store. Request bodies are bounded and duplicate or unknown parameters are rejected. The management plane stores hash-linked evidence and uses tenant-scoped PostgreSQL platform records with atomic create and compare-and-swap. Raw tokens and client secrets do not enter those records.

Verification

Run focused authority and protocol tests:

Internal implementation checks are omitted from this public guide.

Compile the Docker-tagged suites without starting containers:

Internal implementation checks are omitted from this public guide.

The PostgreSQL Docker suites exercise API-access, workload-assertion, and OIDC restart boundaries. The new unit and fixture tests prove rotation, replay, one-time JTI consumption, and signed two-stage exchange. Runtime Docker execution remains deferred until unrelated active workloads release host memory; this page does not present compiled tests as executed container evidence.