Get an access token
const url = 'http://localhost:8080/oauth/token';const options = { method: 'POST', headers: { Authorization: 'Basic <credentials>', 'Content-Type': 'application/x-www-form-urlencoded' }, body: new URLSearchParams({grant_type: 'client_credentials', scope: 'accounts:read operations:write'})};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url http://localhost:8080/oauth/token \ --header 'Authorization: Basic <credentials>' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data grant_type=client_credentials \ --data 'scope=accounts:read operations:write'OAuth 2.0 client credentials (RFC 6749 §4.4). Authenticate with HTTP Basic: the credential’s ID as the user name and its secret as the password. Credentials in the body are refused. The token lives 15 minutes by default and carries the scopes the credential’s roles grant (the permission matrix, ADR-0017), or the subset asked for with scope. Revoking the credential, or disabling its client, ends the token at once.
Errors are RFC 6749 §5.2 objects ({"error": "invalid_client"}), not Problem Details. An unknown credential, a revoked one and a wrong secret are all 401 invalid_client.
Authorizations
Section titled “Authorizations”Request Bodyrequired
Section titled “Request Bodyrequired”object
Space-separated scopes, at most those the credential’s roles grant. Omitted: all of them.
Example
grant_type=client_credentials&scope=accounts%3Aread+operations%3AwriteResponses
Section titled “Responses”Issued
object
Seconds until the token expires.
The scopes granted, space-separated.
Example
{ "access_token": "mzt_4f9c2a8e7b1d3f5a6c8e0b2d4f6a8c0e2b4d6f8a0c2e4b6d8f0a2c4e6b8d0f2a", "token_type": "Bearer", "expires_in": 900, "scope": "accounts:read operations:write"}Headers
Section titled “Headers”no-store: a token response is never cached (RFC 6749 §5.1).
Bad request
object
Examples
{ "error": "unsupported_grant_type", "error_description": "Only grant_type=client_credentials is supported."}{ "error": "invalid_scope", "error_description": "The credential's roles do not grant \"periods:close\"."}Bad client
object
Example
{ "error": "invalid_client", "error_description": "Client authentication failed."}Headers
Section titled “Headers”Basic realm="mezgeb".
Slow down
object
Example
{ "error": "slow_down", "error_description": "Too many token requests for this credential; retry after Retry-After seconds."}Headers
Section titled “Headers”Seconds to wait before retrying.
Unavailable
object
Example
{ "error": "temporarily_unavailable", "error_description": "The token could not be issued; retry."}Headers
Section titled “Headers”Seconds to wait before retrying.