Skip to main content

Jwt mappings API

This page documents the 5 gateway endpoints tagged jwt_mappings 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/jwt/key/mapping/deleteDelete a JWT key mapping
GET/jwt/key/mapping/infoGet one JWT key mapping
GET/jwt/key/mapping/listList JWT key mappings
POST/jwt/key/mapping/newMap a JWT claim value to a virtual key
POST/jwt/key/mapping/updateChange a JWT key mapping

Endpoints​

POST /jwt/key/mapping/delete​

Delete a JWT key mapping

Remove the mapping. Tokens that carried its claim stop resolving to the key right away. Proxy admins only.

Request body (application/json, schema DeleteJWTKeyMappingRequest):

FieldTypeRequiredDescription
idstringYesId

Example request:

curl -X POST "http://localhost:4000/jwt/key/mapping/delete" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"id": "jkm-01J8Z"
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json JWTKeyMappingDeleted
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
404No object with that id is visible to the callerapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError

Response fields (200):

FieldTypeRequiredDescription
status"success"YesStatus

GET /jwt/key/mapping/info​

Get one JWT key mapping

One mapping by id, without the hashed key. Proxy admins and admin viewers.

Parameters:

NameInTypeRequiredDescription
idquerystringYes

Example request:

curl -X GET "http://localhost:4000/jwt/key/mapping/info?id=id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful Responseapplication/json JWTKeyMappingResponse
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
404No object with that id is visible to the callerapplication/json ErrorDetail
422Validation Errorapplication/json HTTPValidationError

Response fields (200):

FieldTypeRequiredDescription
created_atstringYesCreated At
created_bystring or nullNoCreated By
descriptionstring or nullNoDescription
idstringYesId
is_activebooleanYesIs Active
jwt_claim_namestringYesJwt Claim Name
jwt_claim_valuestringYesJwt Claim Value
jwt_issuerstring or nullNoJwt Issuer
updated_atstringYesUpdated At
updated_bystring or nullNoUpdated By

GET /jwt/key/mapping/list​

List JWT key mappings

Mappings newest first, without the hashed key. Proxy admins and admin viewers.

Parameters:

NameInTypeRequiredDescription
pagequeryintegerNoPage number
sizequeryintegerNoPage size

Example request:

curl -X GET "http://localhost:4000/jwt/key/mapping/list" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200Successful Responseapplication/json any
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

POST /jwt/key/mapping/new​

Map a JWT claim value to a virtual key

Make requests whose JWT carries jwt_claim_name equal to jwt_claim_value run as the given virtual key, with that key's models, budget and spend attribution. Pass exactly one of key (the plaintext key) or token (its SHA-256 hash). jwt_issuer limits the mapping to tokens from one issuer, and leaving it out matches every configured issuer. Proxy admins only, and the gateway needs a license that includes JWT auth.

Request body (application/json, schema CreateJWTKeyMappingRequest):

FieldTypeRequiredDescription
descriptionstring or nullNoDescription
jwt_claim_namestringYesJwt Claim Name
jwt_claim_valuestringYesJwt Claim Value
jwt_issuerstring or nullNoJwt Issuer
keystring or nullNoKey
tokenstring or nullNoToken

Example request:

curl -X POST "http://localhost:4000/jwt/key/mapping/new" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"description": "Billing service",
"jwt_claim_name": "azp",
"jwt_claim_value": "billing-service",
"jwt_issuer": "https://login.example.com",
"key": "sk-9f3a2c7e41b8d605"
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json JWTKeyMappingResponse
400The request is malformed or breaks a rule named in the detailapplication/json ErrorDetail
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
created_atstringYesCreated At
created_bystring or nullNoCreated By
descriptionstring or nullNoDescription
idstringYesId
is_activebooleanYesIs Active
jwt_claim_namestringYesJwt Claim Name
jwt_claim_valuestringYesJwt Claim Value
jwt_issuerstring or nullNoJwt Issuer
updated_atstringYesUpdated At
updated_bystring or nullNoUpdated By

POST /jwt/key/mapping/update​

Change a JWT key mapping

Point the mapping at another key, change its issuer or description, or pause it with is_active: false. The claim name and value cannot change, so delete and recreate a mapping to move it to another claim. Cached lookups for the old and new claim are dropped once the change is written. Proxy admins only.

Request body (application/json, schema UpdateJWTKeyMappingRequest):

FieldTypeRequiredDescription
descriptionstring or nullNoDescription
idstringYesId
is_activeboolean or nullNoIs Active
jwt_issuerstring or nullNoJwt Issuer
keystring or nullNoKey
tokenstring or nullNoToken

Example request:

curl -X POST "http://localhost:4000/jwt/key/mapping/update" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"description": "Billing service, rotated key",
"id": "jkm-01J8Z",
"key": "sk-9876wxyz5432stuv"
}'

Responses:

StatusDescriptionBody
200Successful Responseapplication/json JWTKeyMappingResponse
400The request is malformed or breaks a rule named in the detailapplication/json ErrorDetail
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
404No object with that id is visible to the callerapplication/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
created_atstringYesCreated At
created_bystring or nullNoCreated By
descriptionstring or nullNoDescription
idstringYesId
is_activebooleanYesIs Active
jwt_claim_namestringYesJwt Claim Name
jwt_claim_valuestringYesJwt Claim Value
jwt_issuerstring or nullNoJwt Issuer
updated_atstringYesUpdated At
updated_bystring or nullNoUpdated By