Skip to content
Migrating from NextAuth.js v4? Read our migration guide.
Getting Started
Providers
Keycloak

Keycloak Provider

Resources

Setup

Callback URL

https://example.com/api/auth/callback/keycloak

Environment Variables

AUTH_KEYCLOAK_ID
AUTH_KEYCLOAK_SECRET
AUTH_KEYCLOAK_ISSUER

Configuration

/auth.ts
import NextAuth from "next-auth"
import Keycloak from "next-auth/providers/keycloak"
 
export const { handlers, auth, signIn, signOut } = NextAuth({
  providers: [Keycloak],
})

Enable the “Client Authentication” option to retrieve your client secret in the Credentials tab.

Prior to v20, create an openid-connect client in Keycloak with “confidential” as the “Access Type”.

  • Issuer should include the realm – e.g. https://my-keycloak-domain.com/realms/My_Realm
Auth.js © Balázs Orbán and Team - 2024