oauth

Generate and manage OAuth tokens.

Authorize a user

GET https://mastodon.example/oauth/authorize

Displays an authorization form to the user. If approved, it will create and return an authorization code, then redirect to the desired redirect_uri, or show the authorization code if urn:ietf:wg:oauth:2.0:oob was requested. The authorization code can be used while requesting a token to obtain access to user-level methods.

Request Body

Name
Type
Description

force_login

string

Added in 2.6.0. Forces the user to re-login, which is necessary for authorizing with multiple accounts from the same instance.

response_type

string

Should be set equal to code.

client_id

string

Client ID, obtained during app registration.

redirect_uri

string

Set a URI to redirect the user to. If this parameter is set to urn:ietf:wg:oauth:2.0:oob then the authorization code will be shown instead. Must match one of the redirect URIs declared during app registration.

scope

string

List of requested OAuth scopes, separated by spaces (or by pluses, if using query parameters). Must be a subset of scopes declared during app registration. If not provided, defaults to read.

redirect_uri?code=qDFUEaYrRK5c-HNmTCJbAzazwLRInJ7VHFat0wcMgCU

Obtain a token

POST https://mastodon.example/oauth/token

Returns an access token, to be used during API calls that are not public.

Request Body

Name
Type
Description

client_id

string

Client ID, obtained during app registration

client_secret

string

Client secret, obtained during app registration

redirect_uri

string

Set a URI to redirect the user to. If this parameter is set to urn:ietf:wg:oauth:2.0:oob then the token will be shown instead. Must match one of the redirect URIs declared during app registration.

scope

string

List of requested OAuth scopes, separated by spaces. Must be a subset of scopes declared during app registration. If not provided, defaults to read.

code

string

A user authorization code, obtained via /oauth/authorize

grant_type

string

Set equal to authorization_code if code is provided in order to gain user-level access. Otherwise, set equal to client_credentials to obtain app-level access only.

{
  "access_token": "ZA-Yj3aBD8U8Cm7lKUp-lm9O9BmDgdhHzDeqsY8tlL0",
  "token_type": "Bearer",
  "scope": "read write follow push",
  "created_at": 1573979017
}

Revoke token

POST https://mastodon.example/oauth/revoke

Revoke an access token to make it no longer valid for use.

Request Body

Name
Type
Description

client_id

string

Client ID, obtained during app registration

client_secret

string

Client secret, obtained during app registration

token

string

The previously obtained token, to be invalidated

{}

Last updated

Was this helpful?