Skip to content

A project with next + keycloak authentication + tailwind installed. Ideal if you neeed a fast auth in your next project or inspiration.

Notifications You must be signed in to change notification settings

santiblanko/keycloak-nextjs-auth

Repository files navigation

Keycloak + NextJS + Tailwind.

Check this example.

In this example I create a project with next + keycloak authentication + tailwind installed. Ideal if you neeed a fast auth in your next project. You can use a free keycloak server like cloud iam.

I don't want to use a library for manage auth. I try to implement auth with keycloak from sratch and this is the result. I create a next middleware for intercept the auth pages and validate the token of protected pages. Also I call this other endpoint for authenticate the request and keycloak call a callback endpoint with the tokens and then create cookies.

const signInUrl = `${props.KEYCLOAK_BASE_URL}/auth/realms/${props.KEYCLOAK_REALM}/protocol/openid-connect/auth?client_id=${props.KEYCLOAK_CLIENT_ID}&scope=openid%20profile%20email%20offline_access&response_type=code&redirect_uri=${props.KEYCLOAK_REDIRECT_URI}`;

If you need a keycloack theme with tailwind integrated see my other repo. If you want to add auth to a container check my other implementation with oauth2proxy .

Also I create a tailwindui theme for keycloak. check the repo.

Env variables

KEYCLOAK_CLIENT_SECRET=wITlOh2V8bOGFKx3mD3RDk0nD1FNYb6Q
KEYCLOAK_CLIENT_ID=my-client
KEYCLOAK_BASE_URL=http://localhost:8080
KEYCLOAK_REALM=master

Run.

yarn dev

If this implementation looks great you can share a beer using patreon or send me bitcoins.

Bitcoin direction:

31p39e3AtdEv8T2aU9y9D1XH9Wc5HEtRte

I will be enormously grateful. :) Also I am available for capacitations, keycloak courses and projects!! Whatsapp :) +573233729549

About

A project with next + keycloak authentication + tailwind installed. Ideal if you neeed a fast auth in your next project or inspiration.

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published