3

Using Keycloak to authorize & authenticate Spring Boot application

 2 years ago
source link: https://dev.to/datmt/using-keycloak-to-authorize-authenticate-spring-boot-application-4d9
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Cover image for Using Keycloak to authorize & authenticate Spring Boot application
Mạnh Đạt

Posted on Nov 21

Using Keycloak to authorize & authenticate Spring Boot application

Recently I started an SaaS project. For any project, one of the first problems you need to solve is authentication and authorization. It's 2021 and it's quite foolish to build your own system to log users in and check their role. After a few weeks study available options, I decided to go with Spring Boot & Keycloak.

If you don't know Keycloak, it's an opensource project that help you quickly setup authentication & authorization for your app. In my case, this is a perfect fit.

Project requirements

  • App has three roles member, moderator, admin
  • API must have endpoints to create user and let user login
  • Endpoints authorization could be configure with path prefix (for example /admin...) or by developer specifies the role allowed for each endpoint (using @RolesAllowed)

The code

The project is available here on Github, you can checkout and try it right away:
https://github.com/datmt/Keycloak-Spring-Boot-Login-Create-User

Need tutorial?

If you need step by step tutorial, check my post here:

https://datmt.com/backend/integrate-keycloak-with-spring-boot-step-by-step/

Conclusion

Keycloak is a mature solution for authorization and authentication. It has quite many customization that can fit into various needs. If you can use it in your project, it can save you a great deal of valuable time.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK