Authorization Code Grant
Authenticating with the AniList API using the Authorization Code Grant.
Last updated
Authenticating with the AniList API using the Authorization Code Grant.
Last updated
Once you have , you can use your client ID and client secret to request an authorization code.
The first step is to redirect the user to the authorization URL https://anilist.co/api/v2/oauth/authorize
with the required parameters.
::: code-group
:::
client_id
- The client ID of your application
redirect_uri
- The redirect URI of your application.
::: warning The redirect URI you use in your authorization request must exactly match the redirect URI you used in your application settings. :::
Once the user has been redirected, they will be shown a page asking them to approve your application. If the user is not logged in, they will be prompted to log in first.
Once the user has approved your application, they will be redirected back to the redirect URI you specified. Their redirect will contain a code
query parameter representing the authorization code. In the next step, you will exchange this code for an access token.
Once you have an authorization code, you can exchange it for an access token. To do this, you will need to make a POST request to the https://anilist.co/api/v2/oauth/token
endpoint. The request body should include the authorization code that was issued by AniList along with the client ID and client secret of your application.
::: code-group <<< @/guide/snippets/auth/authorization-code/javascript.js{js:line-numbers} [Javascript] <<< @/guide/snippets/auth/authorization-code/php.php{php:line-numbers} [PHP] :::
client_id
- The client ID of your application
client_secret
- The client secret of your application
redirect_uri
- The redirect URI of your application
code
- The authorization code received from the user
The response will contain an access_token
field with a JWT token. With this token, you can to the AniList API.