Skip to content

This example demonstrates how to integrate NextAuth.js with Keycloak in a Next.js application for authentication and session management. It covers setting up Keycloak as an OAuth provider, configuring NextAuth in a Next.js project, handling user sessions, and protecting API routes and pages with authentication.

Notifications You must be signed in to change notification settings

Hareesh108/next-auth-keycloak-with-nextjs-example

Repository files navigation

NextAuth v5 + Keycloak Integration Example (Next js and Typescript)

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

🔑 Key Features

  • 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

.env.local

  • AUTH_KEYCLOAK_ID=

  • AUTH_KEYCLOAK_SECRET=

  • AUTH_KEYCLOAK_ISSUER=

  • AUTH_SECRET=

  • NODE_ENV="development"

About

This example demonstrates how to integrate NextAuth.js with Keycloak in a Next.js application for authentication and session management. It covers setting up Keycloak as an OAuth provider, configuring NextAuth in a Next.js project, handling user sessions, and protecting API routes and pages with authentication.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published