Skip to main content

post /token

Post token

Endpoint for creating new tokens for the current user.

The user is identified by uniqueUserIdentifier and password, not by the request’s bearer token; this endpoint can therefore also be called anonymously to obtain a first token.

The optional lifetimeInSeconds property is silently clamped to the server-configured token.minLifetimeInSeconds and token.maxLifetimeInSeconds bounds. If omitted, token.defaultLifetimeInSeconds is used.

The optional list capabilities limits what the token may do, see roles and capabilities. Tokens have no capabilities by default. The wildcard * can not be requested (400 Bad Request), and capabilities which the user does not hold are refused with 403 Forbidden. The capabilities are set once and can not be changed afterwards.

Note: The response is not an Element, it only contains the new token in the token property. Store it securely; it can not be retrieved again afterwards. Use GET /token or GET /me to inspect the resulting elements instead.

Request

Basic request

curl \
-H 'Content-Type: application/json' \
-d '{
"type": "Token",
"uniqueUserIdentifier": "test@example.com",
"password": "1234"
}' \
https://api.example.com/token
import requests
url = "https://api.example.com/token"
payload = {
"type": "Token",
"uniqueUserIdentifier": "test@example.com",
"password": "1234"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const url = 'https://api.example.com/token';
const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: '{"type":"Token","uniqueUserIdentifier":"test@example.com","password":"1234"}'
};
try {
const response = await fetch(url, options);
const data = await response.json();
console.log(data);
} catch (error) {
console.error(error);
}
<?php
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'https://api.example.com/token', [
'body' => '{"type": "Token", "uniqueUserIdentifier": "test@example.com", "password": "1234"}',
'headers' => [
'Content-Type' => 'application/json',
],
]);
echo $response->getBody();

Request with capabilities

curl \
-H 'Content-Type: application/json' \
-d '{
"type": "Token",
"uniqueUserIdentifier": "test@example.com",
"password": "1234",
"capabilities": [
"role.assign"
]
}' \
https://api.example.com/token
import requests
url = "https://api.example.com/token"
payload = {
"type": "Token",
"uniqueUserIdentifier": "test@example.com",
"password": "1234",
"capabilities": ["role.assign"]
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const url = 'https://api.example.com/token';
const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: '{"type":"Token","uniqueUserIdentifier":"test@example.com","password":"1234","capabilities":["role.assign"]}'
};
try {
const response = await fetch(url, options);
const data = await response.json();
console.log(data);
} catch (error) {
console.error(error);
}
<?php
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'https://api.example.com/token', [
'body' => '{"type": "Token", "uniqueUserIdentifier": "test@example.com", "password": "1234", "capabilities": ["role.assign"]}',
'headers' => [
'Content-Type' => 'application/json',
],
]);
echo $response->getBody();

Response

201 · Without capabilities

Token without capabilities.

201 · With capabilities

Token which was created with a list of requested capabilities.

400 · Bad Request

General issues with the user provided request, e.g. missing properties, malformed properties, failing validation logic etc.

401 · Unauthorized

The provided token is either invalid or expired.

403 · Forbidden

The user does not hold a requested capability.

{
"type": "_TokenResponse",
"token": "secret-token:KvHFdoF9XIoJm0v4UdbUeV"
}
Access-Control-Allow-Headers: Authorization, Content-Type, If-Match, If-None-Match
Access-Control-Allow-Methods: DELETE, GET, HEAD, OPTIONS, POST
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: ETag
Allow: DELETE, GET, HEAD, OPTIONS, POST
Cache-Control: no-cache, private
X-Powered-By: Ember Nexus API
{
"type": "object",
"description": "Response returned after successfully creating a new token. Unlike other endpoints, this is not an Element.",
"required": [
"type",
"token"
],
"properties": {
"type": {
"type": "string",
"enum": [
"_TokenResponse"
],
"example": "_TokenResponse"
},
"token": {
"type": "string",
"description": "The newly created token, in the RFC 8959 `secret-token:` scheme. It is only ever shown once; use `GET /token` or `GET /me` afterwards to inspect the resulting elements instead.",
"example": "secret-token:PIPeJGUt7c00ENn8a5uDlc"
}
}
}
{
"type": "_TokenResponse",
"token": "secret-token:G9k5WDZ7C9IaiR3EupIR75"
}
Access-Control-Allow-Headers: Authorization, Content-Type, If-Match, If-None-Match
Access-Control-Allow-Methods: DELETE, GET, HEAD, OPTIONS, POST
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: ETag
Allow: DELETE, GET, HEAD, OPTIONS, POST
Cache-Control: no-cache, private
X-Powered-By: Ember Nexus API
{
"type": "object",
"description": "Response returned after successfully creating a new token. Unlike other endpoints, this is not an Element.",
"required": [
"type",
"token"
],
"properties": {
"type": {
"type": "string",
"enum": [
"_TokenResponse"
],
"example": "_TokenResponse"
},
"token": {
"type": "string",
"description": "The newly created token, in the RFC 8959 `secret-token:` scheme. It is only ever shown once; use `GET /token` or `GET /me` afterwards to inspect the resulting elements instead.",
"example": "secret-token:PIPeJGUt7c00ENn8a5uDlc"
}
}
}
{
"type": "https://api.example.com/error/400/missing-property",
"title": "Missing property",
"status": 400,
"instance": "urn:uuid:02IiNr0G8viOVKjLCfR4NIEdgVrLpaxVcZ7BI",
"detail": "Endpoint requires that the request contains property 'type' to be set to a valid type."
}
Access-Control-Allow-Headers: Authorization, Content-Type, If-Match, If-None-Match
Access-Control-Allow-Methods: DELETE, GET, HEAD, OPTIONS, POST
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: ETag
Allow: DELETE, GET, HEAD, OPTIONS, POST
Cache-Control: no-cache, private
X-Powered-By: Ember Nexus API
{
"type": "object",
"description": "Problem Details object, see RFC 9457.",
"properties": {
"type": {
"type": "string",
"format": "uri"
},
"title": {
"type": "string"
},
"status": {
"type": "integer"
},
"detail": {
"type": "string"
},
"instance": {
"type": "string",
"format": "uri",
"description": "URN uniquely identifying the request that produced this problem, as `urn:uuid:<uuid>`."
}
}
}
{
"type": "https://api.example.com/error/401/unauthorized",
"title": "Unauthorized",
"status": 401,
"instance": "urn:uuid:02IiNr0G8viOVKjLCfR4NIEdgVrLpaxVcZ7BI",
"detail": "Authorization for the request failed due to possible problems with the token (incorrect or expired), password (incorrect or changed), the user's unique identifier, or the user's status (e.g., missing, blocked, or deleted)."
}
Access-Control-Allow-Headers: Authorization, Content-Type, If-Match, If-None-Match
Access-Control-Allow-Methods: DELETE, GET, HEAD, OPTIONS, POST
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: ETag
Allow: DELETE, GET, HEAD, OPTIONS, POST
Cache-Control: no-cache, private
X-Powered-By: Ember Nexus API
{
"type": "object",
"description": "Problem Details object, see RFC 9457.",
"properties": {
"type": {
"type": "string",
"format": "uri"
},
"title": {
"type": "string"
},
"status": {
"type": "integer"
},
"detail": {
"type": "string"
},
"instance": {
"type": "string",
"format": "uri",
"description": "URN uniquely identifying the request that produced this problem, as `urn:uuid:<uuid>`."
}
}
}
{
"type": "https://api.example.com/error/403/forbidden",
"title": "Forbidden",
"status": 403,
"instance": "urn:uuid:02IiNr0G8viOVKjLCfR4NIEdgVrLpaxVcZ7BI",
"detail": "Requested endpoint, element or action is forbidden."
}
Access-Control-Allow-Headers: Authorization, Content-Type, If-Match, If-None-Match
Access-Control-Allow-Methods: DELETE, GET, HEAD, OPTIONS, POST
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: ETag
Allow: DELETE, GET, HEAD, OPTIONS, POST
Cache-Control: no-cache, private
X-Powered-By: Ember Nexus API
{
"type": "object",
"description": "Problem Details object, see RFC 9457.",
"properties": {
"type": {
"type": "string",
"format": "uri"
},
"title": {
"type": "string"
},
"status": {
"type": "integer"
},
"detail": {
"type": "string"
},
"instance": {
"type": "string",
"format": "uri",
"description": "URN uniquely identifying the request that produced this problem, as `urn:uuid:<uuid>`."
}
}
}

Request Header

Authorization

optional

Bearer token for user authentication. If omitted, the request is processed as an anonymous user; if provided, the associated user account is used.

Request Body

{
"type": "Token",
"uniqueUserIdentifier": "test@example.com",
"password": "1234",
"lifetimeInSeconds": 3600,
"data": {
"key": "value"
},
"capabilities": [
"role.assign"
]
}
{
"type": "object",
"required": [
"type",
"uniqueUserIdentifier",
"password"
],
"properties": {
"type": {
"type": "string",
"description": "Must be `Token`. No other values are currently possible.",
"enum": [
"Token"
],
"example": "Token"
},
"uniqueUserIdentifier": {
"type": "string",
"description": "Some attribute uniquely identifying a user, normally an email address. The property name used to store it can be configured server-side.",
"example": "test@example.com"
},
"password": {
"type": "string",
"description": "The plain text password of the user.",
"example": "1234"
},
"lifetimeInSeconds": {
"type": "integer",
"description": "Optional requested token lifetime, in seconds. Silently clamped to the server-configured minimum/maximum lifetime. Defaults to the server-configured default lifetime if omitted.",
"example": 3600
},
"data": {
"type": "object",
"description": "Optional, arbitrary properties stored on the new token element.",
"additionalProperties": true,
"example": {
"key": "value"
}
},
"capabilities": {
"type": "array",
"description": "Optional capabilities of the token. Tokens have no capabilities by default. The wildcard `*` can not be requested, and capabilities which the user does not hold are refused. Write once, can not be changed afterwards.",
"items": {
"type": "string"
},
"example": [
"role.assign"
]
}
}
}

Response Header

Access-Control-Allow-Headers

always

Lists the request headers which the endpoint reads and which browsers may send in cross-origin requests. Headers are listed explicitly, as the wildcard does not cover Authorization; resumable upload headers, for example, are only listed by upload endpoints.

Access-Control-Allow-Methods

always

Indicates which HTTP methods are permitted for cross-origin requests, typically returned in preflight responses.

Access-Control-Allow-Origin

always

Specifies which origin may access the resource: the origin of the request (default), or * if cors.allowedOrigins is set to the wildcard. Not sent to origins which are not part of a configured list of cors.allowedOrigins.

Access-Control-Expose-Headers

optional

Lists the response headers which the endpoint can send and which browsers may access from JavaScript beyond the default restricted set. Only headers of the endpoint are listed; the header is omitted if the endpoint has none.

Allow

always

Lists the HTTP methods supported by the endpoint; returned alongside a Method Not Allowed response.

Cache-Control

always

Directives controlling caching behavior for the response.

X-Powered-By

always

Identifies the underlying API implementation.

Access-Control-Allow-Methods

always

Indicates which HTTP methods are permitted for cross-origin requests, typically returned in preflight responses.

Allow

always

Lists the HTTP methods supported by the endpoint; returned alongside a Method Not Allowed response.

Access-Control-Allow-Methods

always

Indicates which HTTP methods are permitted for cross-origin requests, typically returned in preflight responses.

Allow

always

Lists the HTTP methods supported by the endpoint; returned alongside a Method Not Allowed response.

Access-Control-Allow-Methods

always

Indicates which HTTP methods are permitted for cross-origin requests, typically returned in preflight responses.

Allow

always

Lists the HTTP methods supported by the endpoint; returned alongside a Method Not Allowed response.