AniLink - v3.1.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. An empty string is treated as omitted.

      • Optionalsignal: AbortSignal

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

      • Optionaloptions: RequestOptions

        Optional transport settings for the token call; timeout defaults to the shared 10-second token-request timeout and retry defaults to disabled because the authorization code is single-use. Pass an explicit retry policy to opt back in.

      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);