Skip to main content

POST /api/principals/xauth

Create an externally-authenticated (XAuth) principal. Idempotent by exact id.

Creates an XAuth principal, or reports the existing one unchanged.

This route is idempotent because the key server is not. Principal creation performs no uniqueness check on the id, so calling it twice would mint two principals with one identity. This route resolves by exact id first and writes nothing when one exists.

The id is stored VERBATIM and nothing maps it. There is no cross-reference table in this Gateway and none in the key server -- that is the point: the identity must be reproducible from the consuming application alone. namespaced reports whether it carries the recommended <application>:<user id> shape. That shape is not enforced, because enforcing it would be a scoping policy and scoping has not been ruled.

An empty id is refused rather than ignored: the underlying setter ACCEPTS the empty string and CLEARS the stored id with it, so an empty value would blank a column rather than doing nothing.

WARNING: with no roles, the principal holds no operations -- it can be impersonated and can do nothing, not even own a key. Roles are applied here as a genuine second call because the key server clears them on creation whatever is sent.

Authentication

Send the session id as Authorization: Bearer <session id>, and an RFC 9449 DPoP proof in the DPoP header if your session is bound to a key. The two are required together, not as alternatives — see Authenticating and Proving you hold your key.

This surface sets no cookie

There is no session cookie on any response and none is read on any request. Do not set credentials: "include" on a browser fetch.

Request

FieldTypeRequiredDescription
idstringyesThe deterministic, namespaced identity, derived from your own user id. No leading or trailing whitespace and no control characters: it is stored verbatim and it is what an audit row names.
metaInfostringnoA string when present. Omit it to leave the field unset -- the empty string CLEARS it rather than leaving it alone.
rolesarray of stringno16-hex-digit role ids, from GET /api/roles.

Example

{
"id": "...",
"metaInfo": "...",
"roles": [
"..."
]
}

Responses

200

The principal exists, either created now or already present.

FieldTypeRequiredDescription
createdbooleanyesFalse means it already existed and NOTHING was written.
namespacedbooleanyes
requestedRolesarray of stringno
rolesAppliedbooleanno
principalobjectyes
detailstringno

principal object

FieldTypeRequiredDescription
idstringnoThe XAuth id -- a string
principalIdstringnoDecimal string.
systemIdintegerno
metaInfostringno
flagsinteger or nullno
disabledboolean or nullno
roleIdsarray of stringno

Example

{
"created": true,
"namespaced": true,
"requestedRoles": [
"..."
],
"rolesApplied": true,
"principal": {
"id": "...",
"principalId": "...",
"systemId": 0,
"metaInfo": "...",
"flags": 0,
"disabled": true,
"roleIds": [
"..."
]
},
"detail": "..."
}

400

The request was refused before anything was sent to the key server.

Most 400s on this surface carry code: BAD_REQUEST and a detail naming the field and saying what the key server would otherwise have done with it. A large share of them exist because the value would have been ACCEPTED downstream and quietly meant something else -- an empty string that reaches the wire as "mint a new key", a zero-length identifier that names no object, a numeric flag word that clears bits the caller did not name.

401

No live session, or a DPoP proof that did not verify.

SESSION_NOT_FOUND -- the credential names no session this Gateway holds. SESSION_EXPIRED -- it aged out. Both carry reauth: true; obtain a new credential rather than retrying.

PROOF_* -- the sender constraint refused. See the DPoP section of this document for the full table; PROOF_MALFORMED is a 400 and PROOF_REPLAY_CACHE_FULL a 503, and the rest are here.

SCOPED_CREDENTIAL_EXPIRED -- a scoped browser credential passed its fixed lifetime. Use does not extend it: an idle timeout would be refreshed by exactly the traffic a stolen handle produces.

403

Authenticated, and refused. The codes differ in what they say about where the refusal came from: ACCESS_DENIED and PRINCIPAL_DISABLED are the key server's, while NOT_WRITABLE, BUILT_IN_PRINCIPAL, OWN_ACCOUNT and OBJECT_NOT_IN_CREDENTIAL_SCOPE are decided by the Gateway before anything is sent.

409

ROLES_NOT_VERIFIED -- the principal is there and the roles were sent and not refused, and the read-back does not show them.

500

A fault rather than a refusal.

OP_FAILED is the catch-all: the key server refused in words that match no classified pattern, so the Gateway cannot say more than that the operation did not happen. Some key server refusals that are conceptually a caller error arrive here rather than as a 4xx, because the wire carries no distinguishing code -- where a route can recognise one from its message it maps it, and each such mapping is documented on the operation.

502

READBACK_FAILED -- creation was sent and not refused, and the principal was not present when read back by exact id. Do not simply retry: the key server enforces no uniqueness on the id.

503

A capacity ceiling or a missing deployment prerequisite. retryable says which.

A scope of session or process names the ceiling that was hit, and the response carries Retry-After.

Error handling

Every failure answers JSON carrying at least code and detail. Match on codedetail is written for a human debugging the call and its wording is not part of the contract. See the error model.

StatusMeaning
400The request was refused before anything was sent to the key server. Most 400s on this surface carry code: BAD_REQUEST and a detail naming the field and saying what the key server would otherwise have done with it. A large share of them exist because the value would have been ACCEPTED downstream and quietly meant something else -- an empty string that reaches the wire as "mint a new key", a zero-length identifier that names no object, a numeric flag word that clears bits the caller did not name.
401No live session, or a DPoP proof that did not verify. SESSION_NOT_FOUND -- the credential names no session this Gateway holds. SESSION_EXPIRED -- it aged out. Both carry reauth: true; obtain a new credential rather than retrying. PROOF_* -- the sender constraint refused. See the DPoP section of this document for the full table; PROOF_MALFORMED is a 400 and PROOF_REPLAY_CACHE_FULL a 503, and the rest are here. SCOPED_CREDENTIAL_EXPIRED -- a scoped browser credential passed its fixed lifetime. Use does not extend it: an idle timeout would be refreshed by exactly the traffic a stolen handle produces.
403Authenticated, and refused. The codes differ in what they say about where the refusal came from: ACCESS_DENIED and PRINCIPAL_DISABLED are the key server's, while NOT_WRITABLE, BUILT_IN_PRINCIPAL, OWN_ACCOUNT and OBJECT_NOT_IN_CREDENTIAL_SCOPE are decided by the Gateway before anything is sent.
409ROLES_NOT_VERIFIED -- the principal is there and the roles were sent and not refused, and the read-back does not show them.
500A fault rather than a refusal. OP_FAILED is the catch-all: the key server refused in words that match no classified pattern, so the Gateway cannot say more than that the operation did not happen. Some key server refusals that are conceptually a caller error arrive here rather than as a 4xx, because the wire carries no distinguishing code -- where a route can recognise one from its message it maps it, and each such mapping is documented on the operation.
502READBACK_FAILED -- creation was sent and not refused, and the principal was not present when read back by exact id. Do not simply retry: the key server enforces no uniqueness on the id.
503A capacity ceiling or a missing deployment prerequisite. retryable says which. A scope of session or process names the ceiling that was hit, and the response carries Retry-After.