Skip to content
Dashboard

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 Markdown

Get the OAuth server's metadata

get/.well-known/oauth-authorization-server

Authorization server metadata (RFC 8414): where to send people to allow an app, where to trade codes and revoke tokens, and what's supported. OAuth's own shape, not the envelope.

Needs
No token needed
Anyone may call it.
Rate limit
120 a minute
Per address, for this endpoint.
App scope
No access token
An app calls it with its client id.

Response

It answers in OAuth's own shape, not the envelope.

Request
curl 'https://api.hematite.gg/v1/.well-known/oauth-authorization-server'
Example answer
{
  "dataKey": null
}

Revoke 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).

  • tokenstringrequired

    The token to give up: a refresh token revokes its whole grant, an access token only itself.

  • token_type_hintenum

    Which kind it is, to look there first.

    One ofrefresh_tokenaccess_token

  • client_idstringrequired

    The app's id. A confidential app may send it in HTTP Basic instead, with its secret.

  • client_secretstring

    A 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.

Request
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'
Example answer
{}

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_typeenumrequired

    authorization_code to trade a code, refresh_token for the next tokens.

    One ofauthorization_coderefresh_token

  • client_idstringrequired

    The app's id. A confidential app may send it in HTTP Basic instead, with its secret.

  • client_secretstring

    A confidential app's secret, when it doesn't use Basic. An app in a browser or on a phone has none and sends none.

  • codestring

    With authorization_code: the code from the redirect. It works once, within a minute.

  • redirect_uristring

    With authorization_code: the redirect_uri the authorization request had, exactly.

  • code_verifierstring

    With authorization_code: the PKCE verifier whose SHA-256 was the code_challenge.

  • refresh_tokenstring

    With 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.

  • scopestring

    With 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_tokenstring
  • token_type"Bearer"
  • expires_innumber

    Seconds until the access token ends

  • refresh_tokenstring
  • scopestring

    Space-separated, as granted

Request
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'
Example answer
{
  "access_token": "string",
  "token_type": "Bearer",
  "expires_in": 0,
  "refresh_token": "string",
  "scope": "string"
}