mirror of
https://github.com/mastodon/documentation
synced 2025-04-11 22:56:17 +02:00

* add rules * join date on profiles * deprecate follow scope * deprecate identity proofs * familiar followers * use definition lists instead of tables for defining activitypub properties * reformat notifications page into markdown * fix broken links to publicKey header * Application website is now nullable * update environment variables added and removed * fix typo * fix heading level * min_id and max_id can be used at the same time (3.3) * fix typo * new tootctl options * reformat tootctl page to use definition lists for params * add rules and configuration to Instance * fix typo * refactor instance api page * 3.3.0 duration on mutes * 3.3.0 mute_expires_at * improve section headings * 3.4.0 resend email confirmation api * 3.4.0 policy on push subscriptions * 3.4.0 add details to account registration error * refactor accounts api page and start adding relrefs to entity pages * 3.4.0 accounts/lookup api * add see also to accounts methods * add more see-also links * 3.5.0 appeal mod decisions * 3.5.0 reformat reports and add category/rule_ids params * document report entity and missing responses * fix typos * fix relrefs and url schema, add aliases to old urls * add archetypes for new methods/entities * update archetypes with see-also stubs * clearer presentation of rate limits * announcements api methods * refactor apps methods * refactor bookmarks methods + some anchors * refactor conversations methods * custom_emojis methods refactor * anchors * refactor directory methods * refactor domain_blocks methods * add see also to emails methods * fix page relref shortcodes to specific methods + refactor endorsements methods * min_id max_id * refactor favourites methods * refactor featured_tags methods * refactor filters methods, make path params consistent, i18n required shortcode * follow_requests methods * lists methods * markers methods * forgot to add entity links * media methods, also fix formatting of some json errors * mutes methods, add more see-also links * oembed methods * preferences methods * proofs methods * push methods * suggestions methods * 3.5.0 add new trend types, fix formatting * refactor streaming methods * refactor oauth methods * note that streaming api casts payload to string * refactor search methods * refactor polls methods * remove unnecessary link * reformat scheduled_statuses methods * reformat timelines methods * reformat statuses methods * 3.5.0 editing statuses * consistent use of array brackets in form data parameters * update dev setup guide, add vagrant and clean up text * add admin/accounts methods * 3.6 role entity * admin/accounts methods v2 * minor fix * stub admin/reports methods * document admin reports * add 403 example to methods archetype * cleanup entities for admin reports and add new attrs * 3.6.0 domain allows methods + normalize admin entity namespace * fix search-and-replace error * add aliases for admin entities * 3.6.0 canonical email blocks entity * 3.5.0 admin/retention api * 3.5.0 add admin::ip doc * 3.5.0 admin/reports * 3.6.0 admin/domain_allows * 3.5.0 admin/dimensions * 3.6.0 permissions and roles * minor formatting fix * add anchor link to headings * checkpoint * add update commands to dev env setup guide * change mentions of v3.6 to v4.0 * tootctl now uses custom roles * fix formatting * v2 instance api * update frontmatter, add better titles to pages * minor wording change * consistency * add more aliases * add placeholders and WIP notices * explain link pagination and stub out todos * switch baseURL to https * 422 on reports with rules but category!=violation * document bug fixes * fix typo * remove duplicate API method definition * s/tootsuite/mastodon for github links * remove unnecessary escaping * s/tootsuite/mastodon in Entity archetype * add missing nullable shortcode * clarify oauth scope when requesting a user token * api/v2/media now synchronous for images * DISALLOW_UNAUTHENTICATED_API_ACCESS * add undocumented env variables * add instance domain blocks and extended description api * add SMTP_ENABLE_STARTTLS * add description to SMTP_ENABLE_STARTTLS * take suggestions from open PRs * normalize links and flavour language * Fully document streaming API based on source code * Add mention of MIME types * bump to ruby 3.0.4 * clarify how to check on async media processing * validation of replies_policy * remove TODOs on admin account action * EmailDomainBlocks * IpBlocks * Admin::DomainBlock * remove TODOs * following hashtags * followed_tags * remove reference to unused parameter * add new oauth scopes for admin blocks and allows * fix command signature for i18n-tasks normalize * reformat code structure page * document fixes for following tags (assume 4.0.3) * Add warning about pre-4.0 hardcoded roles * add note about case sensitivity * remove use of 'simply' from docs * remove reference to silencing * add reference to IDN normalization for verified links * add lang parameter
203 lines
6.0 KiB
Markdown
203 lines
6.0 KiB
Markdown
---
|
|
title: oauth API methods
|
|
description: Generate and manage OAuth tokens.
|
|
menu:
|
|
docs:
|
|
weight: 10
|
|
name: oauth
|
|
parent: methods-apps
|
|
identifier: methods-oauth
|
|
aliases: [
|
|
"/methods/oauth",
|
|
"/api/methods/oauth",
|
|
"/methods/apps/oauth",
|
|
]
|
|
---
|
|
|
|
<style>
|
|
#TableOfContents ul ul ul {display: none}
|
|
</style>
|
|
|
|
## Authorize a user {#authorize}
|
|
|
|
```http
|
|
GET https://mastodon.example/oauth/authorize HTTP/1.1
|
|
```
|
|
|
|
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.
|
|
|
|
**Returns:** String (URL) or HTML response\
|
|
**OAuth:** Public\
|
|
**Version history:**\
|
|
0.1.0 - added\
|
|
2.6.0 - added `force_login`\
|
|
3.5.0 - added `lang`
|
|
|
|
#### Request
|
|
##### Query parameters
|
|
|
|
response_type
|
|
: {{<required>}} String. Should be set equal to `code`.
|
|
|
|
client_id
|
|
: {{<required>}} String. The client ID, obtained during app registration.
|
|
|
|
redirect_uri
|
|
: {{<required>}} 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`.
|
|
|
|
force_login
|
|
: Boolean. Forces the user to re-login, which is necessary for authorizing with multiple accounts from the same instance.
|
|
|
|
lang
|
|
: String. The ISO 639-1 two-letter language code to use while rendering the authorization form.
|
|
|
|
#### Response
|
|
##### 200: OK
|
|
|
|
The authorization code will be returned as a query parameter named `code`.
|
|
|
|
```http
|
|
redirect_uri?code=qDFUEaYrRK5c-HNmTCJbAzazwLRInJ7VHFat0wcMgCU
|
|
```
|
|
|
|
##### 400: Client error
|
|
|
|
If the authorization code is incorrect or has been used already, the request will fail.
|
|
|
|
```json
|
|
{
|
|
"error": "invalid_grant",
|
|
"error_description": "The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client."
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## Obtain a token {#token}
|
|
|
|
```http
|
|
POST https://mastodon.example/oauth/token HTTP/1.1
|
|
```
|
|
|
|
Obtain an access token, to be used during API calls that are not public.
|
|
|
|
**Returns:** [Token]({{< relref "entities/token" >}})\
|
|
**OAuth:** Public\
|
|
**Version history:**\
|
|
0.1.0 - added
|
|
|
|
#### Request
|
|
##### Form data parameters
|
|
|
|
grant_type
|
|
: {{<required>}} 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.
|
|
|
|
code
|
|
: String. A user authorization code, obtained via [GET /oauth/authorize](#authorize).
|
|
|
|
client_id
|
|
: {{<required>}} String. The client ID, obtained during app registration.
|
|
|
|
redirect_uri
|
|
: {{<required>}} 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 (or by pluses, if using query parameters). If `code` was provided, then this must be equal to the `scope` requested from the user. Otherwise, it must be a subset of `scopes` declared during app registration. If not provided, defaults to `read`.
|
|
|
|
#### Response
|
|
##### 200: OK
|
|
|
|
Store this access_token for later use with auth-required methods. The token should be passed as an HTTP `Authorization` header when making API calls, with the value `Bearer access_token`
|
|
|
|
```json
|
|
{
|
|
"access_token": "ZA-Yj3aBD8U8Cm7lKUp-lm9O9BmDgdhHzDeqsY8tlL0",
|
|
"token_type": "Bearer",
|
|
"scope": "read write follow push",
|
|
"created_at": 1573979017
|
|
}
|
|
```
|
|
|
|
##### 400: Client error
|
|
|
|
If you try to request a scope that was not included when registering the app, the request will fail.
|
|
|
|
```json
|
|
{
|
|
"error": "invalid_scope",
|
|
"error_description": "The requested scope is invalid, unknown, or malformed."
|
|
}
|
|
```
|
|
|
|
##### 401: Unauthorized
|
|
|
|
If client_id and client_secret do not match or are invalid, the request will fail.
|
|
|
|
```json
|
|
{
|
|
"error": "invalid_client",
|
|
"error_description": "Client authentication failed due to unknown client, no client authentication included, or unsupported authentication method."
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## Revoke a token {#revoke}
|
|
|
|
```http
|
|
POST https://mastodon.example/oauth/revoke HTTP/1.1
|
|
```
|
|
|
|
Revoke an access token to make it no longer valid for use.
|
|
|
|
**Returns:** empty object\
|
|
**OAuth:** Public\
|
|
**Version history:**\
|
|
x.x.x - added
|
|
|
|
#### Request
|
|
##### Form data parameters
|
|
|
|
client_id
|
|
: {{<required>}} String. The client ID, obtained during app registration.
|
|
|
|
client_secret
|
|
: {{<required>}} String. The client secret, obtained durign app registration.
|
|
|
|
token
|
|
: {{<required>}} String. The previously obtained token, to be invalidated.
|
|
|
|
#### Response
|
|
##### 200: OK
|
|
|
|
If you own the provided token, the API call will provide an empty response. This operation is idempotent, so calling this API multiple times will still return OK.
|
|
|
|
```json
|
|
{}
|
|
```
|
|
|
|
##### 403: Forbidden
|
|
|
|
If you provide a token you do not own, or no token at all, the API call will return a 403 error.
|
|
|
|
```json
|
|
{
|
|
"error": "unauthorized_client",
|
|
"error_description": "You are not authorized to revoke this token"
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## See also
|
|
|
|
{{< page-relref ref="methods/apps#create" caption="POST /api/v1/apps" >}}
|
|
|
|
{{< caption-link url="https://github.com/mastodon/mastodon/blob/main/app/controllers/oauth/authorizations_controller.rb" caption="app/controllers/oauth/authorizations_controller.rb" >}}
|
|
|
|
{{< caption-link url="https://github.com/mastodon/mastodon/blob/main/app/controllers/oauth/authorized_applications_controller.rb" caption="app/controllers/oauth/authorized_applications_controller.rb" >}}
|
|
|
|
{{< caption-link url="https://github.com/mastodon/mastodon/blob/main/app/controllers/oauth/tokens_controller.rb" caption="app/controllers/oauth/tokens_controller.rb" >}} |