lucadibello / spring-graphql-keycloak-boilerplate

Spring Boot v3 + GraphQL + GraphiQL + KeyCloak boilerplate

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

spring-graphql-keycloak-boilerplate

Description

This is a boilerplate project to create a Spring Boot application with GraphQL and KeyCloak integration.

Features

  • Supported both GraphQL and REST APIs
  • KeyCloak integration with the following features:
    • Single sign-on (SSO)
    • Login
    • Logout
    • Forgot password
    • Register
    • Reset password
    • Admin panel
    • And much more...
  • GraphiQL playground
  • Spring Boot DevTools
  • Already configured with PostgreSQL drivers and JPA

Tech stack

  • Spring Boot v3 (View configuration here):
    • Spring for GraphQL
    • Spring Web
    • Lombok
    • Spring Boot DevTools
    • Spring Data JPA
    • PostgreSQL Driver
  • KeyCloak v21 + Spring Security
  • GraphQL + GraphiQL
  • Maven

Initial setup

  1. Start PostgreSQL container using Docker Compose
docker-compose up -d
  1. Run KeyCloak container
chmod -x ./start-keycloak.sh && ./start-keycloak.sh

After the container is up and running, you can access the KeyCloak admin panel at http://localhost:8082/ with the following credentials:

  • Username: admin
  • Password: admin

Notice: Unfortunately, you can change the username and password by editing the start-keycloak.sh file.

  1. Setup KeyCloak realm and application client

Since KeyCloak is not part of this project, you need to manually setup the KeyCloak realm and application client.

You can follow the official documentation here.

  1. Edit the application.properties file

You need to update the configured KeyCloak realm and client ID (and secret if you have one).

spring.security.oauth2.client.provider.keycloak.issuer-uri=http://localhost:8082/realms/<REALM NAME>
spring.security.oauth2.resourceserver.jwt.issuer-uri=http://localhost:8082/realms/<REALM NAME>
spring.security.oauth2.client.registration.keycloak.client-id=<CLIENT NAME>
spring.security.oauth2.client.registration.keycloak.client-secret=<CLIENT SECRET>
  1. Run the application with Maven
mvn spring-boot:run

About

Spring Boot v3 + GraphQL + GraphiQL + KeyCloak boilerplate


Languages

Language:Java 90.8%Language:Shell 9.2%