Skip to content

Get an access token

POST
/oauth/token
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.

Media typeapplication/x-www-form-urlencoded
object
grant_type
required
string
Allowed values: client_credentials
scope

Space-separated scopes, at most those the credential’s roles grant. Omitted: all of them.

string
<= 1024 characters

Example

grant_type=client_credentials&scope=accounts%3Aread+operations%3Awrite

Issued

Media typeapplication/json
object
access_token
required
string
/^mzt_[0-9a-f]{64}$/
token_type
required
string
Allowed values: Bearer
expires_in
required

Seconds until the token expires.

integer
>= 1
scope
required

The scopes granted, space-separated.

string

Example

{
"access_token": "mzt_4f9c2a8e7b1d3f5a6c8e0b2d4f6a8c0e2b4d6f8a0c2e4b6d8f0a2c4e6b8d0f2a",
"token_type": "Bearer",
"expires_in": 900,
"scope": "accounts:read operations:write"
}
Cache-Control
string
Allowed values: no-store

no-store: a token response is never cached (RFC 6749 §5.1).

Bad request

Media typeapplication/json
object
error
required
string
Allowed values: invalid_request invalid_client unsupported_grant_type invalid_scope temporarily_unavailable slow_down
error_description
string

Examples

{
"error": "unsupported_grant_type",
"error_description": "Only grant_type=client_credentials is supported."
}

Bad client

Media typeapplication/json
object
error
required
string
Allowed values: invalid_request invalid_client unsupported_grant_type invalid_scope temporarily_unavailable slow_down
error_description
string

Example

{
"error": "invalid_client",
"error_description": "Client authentication failed."
}
WWW-Authenticate
string

Basic realm="mezgeb".

Slow down

Media typeapplication/json
object
error
required
string
Allowed values: invalid_request invalid_client unsupported_grant_type invalid_scope temporarily_unavailable slow_down
error_description
string

Example

{
"error": "slow_down",
"error_description": "Too many token requests for this credential; retry after Retry-After seconds."
}
Retry-After
integer
>= 1

Seconds to wait before retrying.

Unavailable

Media typeapplication/json
object
error
required
string
Allowed values: invalid_request invalid_client unsupported_grant_type invalid_scope temporarily_unavailable slow_down
error_description
string

Example

{
"error": "temporarily_unavailable",
"error_description": "The token could not be issued; retry."
}
Retry-After
integer
>= 1

Seconds to wait before retrying.