SpringBoot OAuth2 with keycloak for Bearer Client

Ravinder Thirumala
5 min readFeb 13, 2022

Keycloak is an open-source Identity and Access Management (IAM) solution aimed at modern applications and services. Keycloak provides out-of-the-box authentication and authorization services as well as advanced features like User Federation, Identity Brokering, and Social Login.

To Secure SpringBoot app with Keycloak we can use Keycloak SpringBoot adapter JAR as dependency and provide some configurations in
application.properties, you can find more info about using spring-boot-adapter in Keycloak Docs.

For long time Spring Security provides support for OAuth 2.0 and OpenID Connect. We can also use Spring Boot OAuth2 for securing Spring Boot applications with Keycloak. For better integration with Spring security, it is recommended to use Spring OAuth2.

In this article we will see how to use spring-boot-starter-oauth2-resource-server to integrate our SpringBoot application, which is a resource server/API server with Keycloak.

To understand better, Let’s look at a sequence diagram, In this article we will be demonstating Steps 3–7. Keycloak is our Autherization Server and SpringBoot application is the resource Server.

What is Resource Server.

--

--