A demonstration of integrating Keycloak authentication with Next.js using NextAuth v5 (Auth.js). This example covers token refresh, session management, and secure API calls for both server and client components
- Keycloak OAuth 2.0/OpenID Connect integration with NextAuth v5
- Auto-refresh expired access tokens using refresh tokens
- Server-side session validation with JWT callbacks
- Client-side token expiration checks and reactive handling
- Secure API routes with authenticated access
- Error handling for token refresh failures
-
AUTH_KEYCLOAK_ID=
-
AUTH_KEYCLOAK_SECRET=
-
AUTH_KEYCLOAK_ISSUER=
-
AUTH_SECRET=
-
NODE_ENV="development"