Implements OpenID Connect.

For usage, see OAuth 2.0 provider with PKCE.

import { Keycloak } from "arctic";

const realmURL = "";

const keycloak = new Keycloak(realmURL, clientId, clientSecret, redirectURI);
const url: URL = await keycloak.createAuthorizationURL(state, codeVerifier, {
	// optional
const tokens: KeycloakTokens = await keycloak.validateAuthorizationCode(code);
const tokens: KeycloakTokens = await keycloak.refreshAccessToken(refreshToken);

Get user profile

Add the profile scope. Optionally add the email scope to get user email.

const url = await keycloak.createAuthorizationURL(state, codeVerifier, {
	scopes: ["profile", "email"]

Parse the ID token or use the userinfo endpoint.

const tokens = await keycloak.validateAuthorizationCode(code, codeVerifier);
const response = await fetch("", {
	headers: {
		Authorization: `Bearer ${tokens.accessToken}`
const user = await response.json();