Coder Social home page Coder Social logo

spring-boot-keycloak's Introduction

Spring boot keycloak example

This example application will show you how you can protect your Spring Boot application with Keycloak.

Setting up your Keycloak

Setting up your own Keycloak application is easy. Either install the right docker image or download the executable and run it on your preferred server. The only hard step is to enable https. The easiest thing to do is to use nginx and creating the right certificates using let's encrypt.

If you're not going to create your own Keycloak, just use the one provided by switchfully at https://Keycloak.switchfully.com

Keycloak configuration

Next up we need to configure our Keycloak.


First either select or create a new realm. A security realm is how Keycloak groups things together. Realms are mutually exclusive, so you cannot access users from one realm in another realm.

Then select or create a client. A client is the representation of your application in Keycloak. A few things need to be configured here:

  • The access type: confidential/public
    • public means you don't need a client secret, confidential means you do.
  • Valid Redirect URIs: the allowed url(s) of your backend application. Put * here to allow everything.
  • Web Origins: the allowed url(s) of your frontend application. Put * here to allow everything.
  • Roles: the roles you are going to use in your application

Lastly create one or more users in the Users menu.

  • Go to Role Mapping -> Client Roles and add the appropriate roles for your users
  • Enable your user by either selecting User Enabled or Resetting their password.

Setting up your Spring Boot application

Keycloak dependencies

At the following dependency to your spring-boot project

<dependency>
    <groupId>org.keycloak</groupId>
    <artifactId>keycloak-spring-boot-starter</artifactId>
    <version>13.0.1</version>
</dependency>

Now add the following properties to your project

keycloak.auth-server-url=<keycloak_url>auth/
keycloak.realm=<realm_name>
keycloak.resource=<client_name>
keycloak.credentials.secret=<client_secret_if_confidential_client>
keycloak.ssl-required=external

spring-boot-keycloak's People

Contributors

thomas-artois avatar

Watchers

 avatar

Forkers

missaouib

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.