POST /api/v1/tokens
Creates a new tokens resource.
This endpoint documentation is generated from the current Fastify route implementation and should be treated as the implementation-level contract for this version of the API.
Source route file: src/api/routes/external/public/tokens/post.ts
Request Method
POST
Base URL
https://api.userdocks.local:5000
Endpoint
/api/v1/tokens
Path Variables
No path variables.
Query Parameters
No query parameters.
HTTP Headers
| Variable | Type | Required | Description |
|---|---|---|---|
Content-Type | string | true | Use application/json for JSON request bodies. |
Request Body
Schema reference: createTokenSchema
Authorization-code exchange body:
{
"client_id": "11111111-1111-1111-1111-111111111111",
"service": "email",
"grant_type": "authorization_code",
"redirect_uri": "https://app.example.com/callback",
"code": "code-from-authorize-step",
"state": "state-from-authorize-step",
"nonce": "nonce-value",
"auth_time": "1735689600",
"scope": "openid profile email"
}
Refresh-token exchange body:
{
"client_id": "11111111-1111-1111-1111-111111111111",
"service": "email",
"grant_type": "refresh_token",
"redirect_uri": "https://app.example.com/callback",
"code": "unused-code-field",
"state": "unused-state-field",
"nonce": "unused-nonce-field",
"auth_time": "1735689600",
"scope": "openid profile email",
"prompt": "none",
"refresh_token": "refresh-token-value"
}
Successful Response
Success status code(s): 201.
{
"kind": "tokens",
"totalItems": 1,
"itemsLength": 1,
"items": [
{
"accessToken": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.access.signature",
"idToken": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.id.signature",
"expiresIn": "1735693200",
"tokenType": "Bearer",
"redirectUri": "https://app.example.com/callback",
"refreshToken": "refresh_token_12345"
}
]
}
Error Responses
| HTTP Status | Example Error |
|---|---|
400 | {"errors":[{"validation":"error","code":"[E4000]","message":"Bad Request / validation error"}]} |
500 | {"errors":[{"validation":"error","code":"[E0000]","message":"Internal Server Error"}]} |
Example
const url = `https://api.userdocks.local:5000/api/v1/tokens`;
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: '{"client_id":"11111111-1111-1111-1111-111111111111","service":"email","grant_type":"authorization_code","redirect_uri":"https://app.example.com/callback","code":"code-from-authorize-step","state":"state-from-authorize-step","nonce":"nonce-value","auth_time":"1735689600","scope":"openid profile email"}',
});
const data = await response.json();
console.log(response.status, data);