Spring Boot | GraphQL | Keycloak

Implementing and Securing a Spring Boot GraphQL API using Keycloak for IAM

Step-by-step guide on implementing and securing Book API application using Keycloak for Identity and Access Management

Ivan Franchin
Javarevisited
Published in
16 min readJul 6, 2023

--

Photo by Brendan Beale on Unsplash

In this article, we will explain how to implement a Spring Boot application called Book API that exposes GraphQL API. Besides, we will secure the GraphQL API and we will use Keycloak as Identity and Access Management (IAM) solution.

GraphQL is a query language for APIs that allows clients to request only the data they need, simplifying data fetching and reducing over-fetching.

So, let’s get started!

Book API

The Book API application has 2 queries and 3 mutations, all of which require authentication and authorization for access.

The application defines two roles: BOOK-API-ADMIN and BOOK-API-USER. These roles control access to specific queries and mutations based on user privileges:

  • The getBooks and getBookById queries can be accessed by users with either the BOOK-API-ADMIN or BOOK-API-USER role;
  • The createBook and deleteBook mutations can only be accessed by users…

--

--

Ivan Franchin
Javarevisited

Lead Software Developer with BS and MS in Computer Science. Writing about Java, Spring, software development in general, and emerging technologies.