Skip to main content

UI Session API

This page documents the 8 gateway endpoints tagged UI Session in the gateway's OpenAPI document. Every example targets a gateway on http://localhost:4000 and authenticates with the SPANWAY_API_KEY environment variable, which holds the master key or a virtual key that has access to the route. Request and response fields are taken from the schema the running gateway publishes at /openapi.json, and the same document is bundled with this site as openapi.json.

MethodPathSummary
POST/session/logoutSign out of the Admin UI
GET/session/meWho the Admin UI session belongs to
GET/user/mfaTwo-factor status of the signed-in user
POST/user/mfa/enrollStart setting up an authenticator app
POST/user/mfa/enroll/confirmFinish two-factor setup with a code
POST/user/mfa/disableTurn off two-factor sign-in
POST/user/mfa/recovery_codesReplace your recovery codes
POST/user/mfa/resetReset a user's two-factor sign-in

Endpoints​

POST /session/logout​

Sign out of the Admin UI

Sign the caller out of the Admin UI for real: the session key created at sign-in is deleted on the server and the session cookie is cleared, so a copied cookie or token stops working at once instead of at the end of SPANWAY_UI_SESSION_DURATION.

Any signed-in Admin UI user may call it for their own session. Only an Admin UI session key is accepted, any other key gets 403, so this route can never delete an ordinary virtual key. Only the session presented is revoked, the user's sessions in other browsers stay signed in. The deleted session key is recorded like any other deleted key. Calling it again for a session that is already gone answers Session already revoked.

Request body (application/json, object):

Example request:

curl -X POST "http://localhost:4000/session/logout" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json SessionLogoutResponse
401No valid key or Admin UI session was presentedapplication/json ProxyError
403The request used a key that is not an Admin UI session keyapplication/json ErrorDetail
500The gateway hit an internal error, usually the database is not connectedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
messagestringYesMessage

GET /session/me​

Who the Admin UI session belongs to

Tell the Admin UI who is signed in: the user id, email and role, how they signed in, whether they must change their password, and when the session ends (expires_at, in Unix seconds). The session key itself is never returned.

The session cookie cannot be read by page scripts, so the Admin UI asks here instead. It answers only when the request authenticated with the key inside that same cookie, any other key or a missing cookie gets 401. Nothing is changed.

Example request:

curl -X GET "http://localhost:4000/session/me" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful Responseapplication/json SessionInfoResponse
401No dashboard session cookie matches the credential this request usedapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
user_idstringYesUser Id
user_emailstring or nullYesUser Email
user_rolestringYesUser Role
login_methodenum: "sso", "username_password"YesLogin Method
premium_userbooleanYesPremium User
disabled_non_admin_personal_key_creationbooleanYesDisabled Non Admin Personal Key Creation
password_reset_requiredbooleanYesPassword Reset Required
auth_header_namestringYesAuth Header Name
expires_atintegerYesExpires At

GET /user/mfa​

Two-factor status of the signed-in user

Whether the signed-in user has two-factor sign-in set up, whether it is required for them, and how many recovery codes they have left.

Example request:

curl -X GET "http://localhost:4000/user/mfa" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful Responseapplication/json MfaStatus
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
enrolledbooleanYesEnrolled
requiredbooleanYesRequired
recovery_codes_remainingintegerYesRecovery Codes Remaining

POST /user/mfa/enroll​

Start setting up an authenticator app

Start setting up an authenticator app for the signed-in user. Returns the otpauth URI to show as a QR code and the secret for manual entry. Nothing is enforced until /user/mfa/enroll/confirm accepts a code.

Request body (application/json, schema MfaEnrollRequest):

FieldTypeRequiredDescription

Example request:

curl -X POST "http://localhost:4000/user/mfa/enroll" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json MfaEnrollment
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
409The object already exists or is in a state that does not allow this changeapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError

Response fields (200):

FieldTypeRequiredDescription
otpauth_uristringYesOtpauth Uri
secretstringYesSecret

POST /user/mfa/enroll/confirm​

Finish two-factor setup with a code

Finish setting up the authenticator app with a current code. Returns ten single-use recovery codes, shown only this once.

Request body (application/json, schema MfaCodeRequest):

FieldTypeRequiredDescription
codestringYesCode

Example request:

curl -X POST "http://localhost:4000/user/mfa/enroll/confirm" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"code": "123456"
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json MfaRecoveryCodes
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError

Response fields (200):

FieldTypeRequiredDescription
recovery_codesarray of stringYesRecovery Codes

POST /user/mfa/disable​

Turn off two-factor sign-in

Turn off two-factor sign-in for the signed-in user with a current code. Refused while it is required for them globally or by one of their organizations.

Request body (application/json, schema MfaCodeRequest):

FieldTypeRequiredDescription
codestringYesCode

Example request:

curl -X POST "http://localhost:4000/user/mfa/disable" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"code": "123456"
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json MfaChanged
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
409The object already exists or is in a state that does not allow this changeapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError

Response fields (200):

FieldTypeRequiredDescription
messagestringYesMessage

POST /user/mfa/recovery_codes​

Replace your recovery codes

Replace the signed-in user's recovery codes with ten new ones, given a current code. The old codes stop working.

Request body (application/json, schema MfaCodeRequest):

FieldTypeRequiredDescription
codestringYesCode

Example request:

curl -X POST "http://localhost:4000/user/mfa/recovery_codes" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"code": "123456"
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json MfaRecoveryCodes
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
409The object already exists or is in a state that does not allow this changeapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError

Response fields (200):

FieldTypeRequiredDescription
recovery_codesarray of stringYesRecovery Codes

POST /user/mfa/reset​

Reset a user's two-factor sign-in

Proxy admins only. Remove a user's two-factor setup and sign them out of every Admin UI session, for a user who lost their authenticator and recovery codes. If two-factor sign-in is required for them they set it up again at their next sign-in.

Request body (application/json, schema MfaResetRequest):

FieldTypeRequiredDescription
user_idstringYesUser Id

Example request:

curl -X POST "http://localhost:4000/user/mfa/reset" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"user_id": "user-123"
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json MfaChanged
401No valid key or Admin UI session was presentedapplication/json ErrorDetail
403The key's role, grants or license do not allow this actionapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError

Response fields (200):

FieldTypeRequiredDescription
messagestringYesMessage