Arctic v1

GitLab

For usage, see OAuth 2.0 provider.

import { GitLab } from "arctic";

const gitlab = new GitLab(clientId, clientSecret, redirectURI, {
	// optional
	domain: "https://example.com"
});
const url: URL = await gitlab.createAuthorizationURL(state, {
	// optional
	scopes
});
const tokens: GitLabTokens = await gitlab.validateAuthorizationCode(code);
const tokens: GitLabTokens = await gitlab.refreshAccessToken(refreshToken);

Get user profile

Add the read_user scope and use the /user endpoint.

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