AniLink - v2.0.0
    Preparing search index...

    Function getAccessToken

    • Exchanges an authorization code for an access token using the authorization-code grant.

      Parameters

      • clientId: string

        The client ID of your AniList API application.

      • clientSecret: string

        The client secret of your AniList API application.

      • code: string

        The authorization code from the redirect URI code query parameter.

      • OptionalredirectUri: string

        The redirect URI registered for your AniList application. This parameter is optional but must match the URI used in buildAuthorizationUrl when AniList requires it.

      • Optionalsignal: AbortSignal

        Optional AbortSignal to cancel the token exchange while it is in flight.

      Returns Promise<AniListTokenResponse>

      A promise that resolves to the token response containing access_token.

      An AniLinkApiError when AniList rejects the exchange, for example with invalid_grant for an invalid or expired code, or an AniLinkNetworkError on transport failure. Errors never include the request body, so the client secret and code are not leaked.

      const { access_token } = await getAccessToken(
      "1234",
      "secret",
      "code-from-redirect",
      "https://example.com/callback"
      );
      const aniLink = new AniLink(access_token);