AniList APIv2 Docs
  • README
  • docs
    • index
    • guide
      • Considerations
      • Introduction
      • Rate Limiting
      • Terms of Use
      • auth
        • Authenticated Requests
        • Authorization Code Grant
        • Implicit Grant
        • Getting Started
      • graphql
        • Connections
        • Errors
        • What is GraphQL?
        • Mutations
        • Pagination
        • What's Next?
        • queries
          • Queries
          • Media List
          • Media
          • User
      • migration
        • version-1
          • Migrating from API v1
          • Api v1 to Api v2 migration queries
    • reference
      • API Reference
      • Root Mutation
      • Root Query
      • enum
        • ActivitySort
        • ActivityType
        • AiringSort
        • CharacterRole
        • CharacterSort
        • ExternalLinkMediaType
        • ExternalLinkType
        • LikeableType
        • MediaFormat
        • MediaListSort
        • MediaListStatus
        • MediaRankType
        • MediaRelation
        • MediaSeason
        • MediaSort
        • MediaSource
        • MediaStatus
        • MediaTrendSort
        • MediaType
        • ModActionType
        • ModRole
        • NotificationType
        • RecommendationRating
        • RecommendationSort
        • ReviewRating
        • ReviewSort
        • RevisionHistoryAction
        • ScoreFormat
        • SiteTrendSort
        • StaffLanguage
        • StaffSort
        • StudioSort
        • SubmissionSort
        • SubmissionStatus
        • ThreadCommentSort
        • ThreadSort
        • UserSort
        • UserStaffNameLanguage
        • UserStatisticsSort
        • UserTitleLanguage
      • input
        • AiringScheduleInput
        • AniChartHighlightInput
        • CharacterNameInput
        • FuzzyDateInput
        • ListActivityOptionInput
        • MediaExternalLinkInput
        • MediaListOptionsInput
        • MediaTitleInput
        • NotificationOptionInput
        • StaffNameInput
      • object
        • ActivityLikeNotification
        • ActivityMentionNotification
        • ActivityMessageNotification
        • ActivityReply
        • ActivityReplyLikeNotification
        • ActivityReplyNotification
        • ActivityReplySubscribedNotification
        • AiringNotification
        • AiringProgression
        • AiringSchedule
        • AiringScheduleConnection
        • AiringScheduleEdge
        • AniChartUser
        • Character
        • CharacterConnection
        • CharacterEdge
        • CharacterImage
        • CharacterName
        • CharacterSubmission
        • CharacterSubmissionConnection
        • CharacterSubmissionEdge
        • Deleted
        • Favourites
        • FollowingNotification
        • FormatStats
        • FuzzyDate
        • GenreStats
        • InternalPage
        • ListActivity
        • ListActivityOption
        • ListScoreStats
        • Media
        • MediaCharacter
        • MediaConnection
        • MediaCoverImage
        • MediaDataChangeNotification
        • MediaDeletionNotification
        • MediaEdge
        • MediaExternalLink
        • MediaList
        • MediaListCollection
        • MediaListGroup
        • MediaListOptions
        • MediaListTypeOptions
        • MediaMergeNotification
        • MediaRank
        • MediaStats
        • MediaStreamingEpisode
        • MediaSubmission
        • MediaSubmissionComparison
        • MediaSubmissionEdge
        • MediaTag
        • MediaTitle
        • MediaTrailer
        • MediaTrend
        • MediaTrendConnection
        • MediaTrendEdge
        • MessageActivity
        • ModAction
        • NotificationOption
        • Page
        • PageInfo
        • ParsedMarkdown
        • Recommendation
        • RecommendationConnection
        • RecommendationEdge
        • RelatedMediaAdditionNotification
        • Report
        • Review
        • ReviewConnection
        • ReviewEdge
        • RevisionHistory
        • ScoreDistribution
        • SiteStatistics
        • SiteTrend
        • SiteTrendConnection
        • SiteTrendEdge
        • Staff
        • StaffConnection
        • StaffEdge
        • StaffImage
        • StaffName
        • StaffRoleType
        • StaffStats
        • StaffSubmission
        • StatusDistribution
        • Studio
        • StudioConnection
        • StudioEdge
        • StudioStats
        • TagStats
        • TextActivity
        • Thread
        • ThreadCategory
        • ThreadComment
        • ThreadCommentLikeNotification
        • ThreadCommentMentionNotification
        • ThreadCommentReplyNotification
        • ThreadCommentSubscribedNotification
        • ThreadLikeNotification
        • User
        • UserActivityHistory
        • UserAvatar
        • UserCountryStatistic
        • UserFormatStatistic
        • UserGenreStatistic
        • UserLengthStatistic
        • UserModData
        • UserOptions
        • UserPreviousName
        • UserReleaseYearStatistic
        • UserScoreStatistic
        • UserStaffStatistic
        • UserStartYearStatistic
        • UserStatistics
        • UserStatisticTypes
        • UserStats
        • UserStatusStatistic
        • UserStudioStatistic
        • UserTagStatistic
        • UserVoiceActorStatistic
        • YearStats
      • union
        • ActivityUnion Reference
        • LikeableUnion
        • NotificationUnion
Powered by GitBook
On this page
  • Redirecting for authorization
  • User Approval
  • Converting codes to tokens
  1. docs
  2. guide
  3. auth

Authorization Code Grant

Authenticating with the AniList API using the Authorization Code Grant.

PreviousAuthenticated RequestsNextImplicit Grant

Last updated 7 months ago

Once you have , you can use your client ID and client secret to request an authorization code.

Redirecting for authorization

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

<a href="https://anilist.co/api/v2/oauth/authorize?client_id={client_id}&redirect_uri={redirect_uri}&response_type=code">Login with AniList</a> 
$query = [
    'client_id' => '{client_id}',
    'redirect_uri' => '{redirect_uri}', // http://example.com/callback
    'response_type' => 'code'    
];


$url = 'https://anilist.co/api/v2/oauth/authorize?' . urldecode(http_build_query($query));

// ...
echo "<a href='$url'>Login with Anilist</a>";

:::

  • 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. :::

User Approval

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.

Converting codes to tokens

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.

created an application
make authenticated requests