Arctic

Twitch

For usage, see OAuth 2.0 provider.

import { Twitch } from "arctic";

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

Get user profile

Use the /users endpoint without passing any arguments.

const tokens = await twitch.validateAuthorizationCode(code);
const response = await fetch("https://api.twitch.tv/helix/users", {
	headers: {
		Authorization: `Bearer ${tokens.accessToken}`,
		"Client-Id": clientId
	}
});
const user = await response.json();

Add the user:read:email scope to get the user's email from the API.

const url = await twitch.createAuthorizationURL(state, {
	scopes: ["user:read:email"]
});