Arctic

Discord

For usage, see OAuth 2.0 provider.

import { Discord } from "arctic";

const discord = new Discord(clientId, clientSecret, redirectURI);
const url: URL = await discord.createAuthorizationURL(state, {
	// optional
	scopes
});
const tokens: DiscordTokens = await discord.validateAuthorizationCode(code);
const tokens: DiscordTokens = await discord.refreshAccessToken(refreshToken);

Get user profile

Add the identify scope and use the /users/@me endpoint.

const url = await discord.createAuthorizationURL(state, {
	scopes: ["identify"]
});
const tokens = await discord.validateAuthorizationCode(code);
const response = await fetch("https://discord.com/api/users/@me", {
	headers: {
		Authorization: `Bearer ${tokens.accessToken}`
	}
});
const user = await response.json();