developers / API reference
OAuth API
The OAuth API: trade codes for app tokens, refresh and revoke them, with every endpoint's fields, who may call it, its rate limit and a curl example.
This page as MarkdownRevoke a token
post/oauth/revoke
OAuth token revocation (RFC 7009): an app gives up a token it holds. A refresh token takes its whole grant with it, an access token only itself. Answers 200 whether or not the token was valid, so it can't be used to test tokens.
- Needs
- No token needed
- Anyone may call it.
- Rate limit
- 30 a minute
- Per address, for this endpoint.
- App scope
- No access token
- An app calls it with its client id.
Form
Sent as application/x-www-form-urlencoded, as OAuth sends it (JSON works too).
tokenstringrequiredThe token to give up: a refresh token revokes its whole grant, an access token only itself.
token_type_hintenumWhich kind it is, to look there first.
One of
refresh_tokenaccess_tokenclient_idstringrequiredThe app's id. A confidential app may send it in HTTP Basic instead, with its secret.
client_secretstringA confidential app's secret, when it doesn't use Basic. An app in a browser or on a phone has none and sends none.
Response
It answers in OAuth's own shape, not the envelope.
curl -X POST 'https://api.hematite.gg/v1/oauth/revoke' \
--data-urlencode "token=$REFRESH_TOKEN" \
--data-urlencode 'token_type_hint=refresh_token' \
--data-urlencode 'client_id=your-app'{}Trade a code or a refresh token for tokens
post/oauth/token
OAuth 2.1's token endpoint: an authorization code (with its PKCE verifier) or a refresh token for an access token and the next refresh token. Send it form-encoded as OAuth does (JSON works too); it answers in OAuth's shape (access_token, error), not the envelope. A code or refresh token used twice revokes every token of its grant, so a client keeps one refresh in flight at a time: across browser tabs, hold a lock while refreshing (the Web Locks API, navigator.locks.request) or let one tab refresh and hand the new tokens to the others (a BroadcastChannel). One leeway, for a tab that missed the new tokens by a moment: a refresh token shown again by its own app within 30 seconds of its first use is exchanged once more, for another pair; the grant stays, and the refresh token its first use gave stays valid too. A third use, or a second one later than that, revokes the grant.
- Needs
- No token needed
- Anyone may call it.
- Rate limit
- 20 a minute
- Per address, for this endpoint.
- App scope
- No access token
- An app calls it with its client id.
Form
Sent as application/x-www-form-urlencoded, as OAuth sends it (JSON works too).
grant_typeenumrequiredauthorization_code to trade a code, refresh_token for the next tokens.
One of
authorization_coderefresh_tokenclient_idstringrequiredThe app's id. A confidential app may send it in HTTP Basic instead, with its secret.
client_secretstringA confidential app's secret, when it doesn't use Basic. An app in a browser or on a phone has none and sends none.
codestringWith authorization_code: the code from the redirect. It works once, within a minute.
redirect_uristringWith authorization_code: the redirect_uri the authorization request had, exactly.
code_verifierstringWith authorization_code: the PKCE verifier whose SHA-256 was the code_challenge.
refresh_tokenstringWith refresh_token: the latest refresh token. Each works once, and once more within 30 seconds of that for a tab that missed the new one; any other second use revokes the grant.
scopestringWith refresh_token: fewer scopes for the new access token, space-separated; never more than were allowed.
Response
It answers in OAuth's own shape, not the envelope: these fields at the top level.
access_tokenstringtoken_type"Bearer"expires_innumberSeconds until the access token ends
refresh_tokenstringscopestringSpace-separated, as granted
curl -X POST 'https://api.hematite.gg/v1/oauth/token' \
--data-urlencode 'grant_type=authorization_code' \
--data-urlencode "code=$CODE" \
--data-urlencode 'redirect_uri=https://yourapp.example/callback' \
--data-urlencode "code_verifier=$CODE_VERIFIER" \
--data-urlencode 'client_id=your-app'{
"access_token": "string",
"token_type": "Bearer",
"expires_in": 0,
"refresh_token": "string",
"scope": "string"
}