Arctic

MyAnimeList

Implements OpenID Connect.

For usage, see OAuth 2.0 provider with PKCE.

import { MyAnimeList } from "arctic";

const mal = new MyAnimeList(clientId, clientSecret, {
	// optional
	redirectURI // only required if you have multiple URIs registered
});
const url: URL = await mal.createAuthorizationURL(state, codeVerifier);
const tokens: MyAnimeListTokens = await mal.validateAuthorizationCode(code, codeVerifier);
const tokens: MyAnimeListTokens = await mal.refreshAccessToken(refreshToken);

Get user profile

Use the /users endpoint.

const tokens = await mal.validateAuthorizationCode(code, codeVerifier);
const response = await fetch("https://api.myanimelist.net/v2/users/@me, {
	headers: {
		Authorization: `Bearer ${tokens.accessToken}`
	}
});
const user = await response.json();