This is a Next.js application prototype to use NextAuth.js with Keycloak.
-
Create a new client in keycloak with the following option:
- Client authentication:
on
- Standard flow: enable
- Direct access grants: disable
- redirect uri:
http://localhost:3000/api/auth/callback/keycloak
- Client authentication:
-
configure
.envrc
export NEXTAUTH_SECRET=$(openssl rand -base64 32)
export KEYCLOAK_CLIENT_ID=<KEYCLOAK_CLIENT_ID>
export KEYCLOAK_CLIENT_SECRET=<EYCLOAK_CLIENT_SECRET>
export KEYCLOAK_ISSUER_URL=http://HOSTNAME:PORT/realms/<REALM_NAME>
- Load env vars
direnv allow
- Start
pnpm dev
- List providers
curl http://localhost:3000/api/auth/providers | jq
- Open Sign-In page: http://localhost:3000