TL; DR
- Purpose: Java authorization server:
- OAuth2.0 authorization code protocol with small-scale permissions (not just a single sign-on server)
- User Management and Authentication: User Database
- Customer Management and Authentication: Keycloak
- Questions: What are the best practices for implementing a Java authorization server with additive permissions supported by Keycloak?
- Which Keycloak adapter / API should I use in my development?
- How should users manage / appear in Keycloak, if at all?
lead time
I am new to Keycloak and although I think I understand the basic principles, it seems to be a rich tool and I am afraid that I may still be mistaken in some aspects of the best ways to use it. Please feel free to correct me.
Context
We are considering introducing an API that requires our users (hereinafter โusersโ) to grant permissions to third-party applications (hereinafter โclientsโ).
Our users are stored in a database-based user management system. For our customers, we are thinking of using Keycloak .
User consent will be granted using the OAuth2.0 Authorization Code Submission Flow. They will log in, indicate which permissions they grant and which they deny, and then the client retrieves the access token that it will use to access the API.
I understand that Keycloak can process the authorization token, but it should not know anything applicative like our permissions. As a result, I thought about creating a custom authorization server that will use Keycloak for all identification / authentication problems, but it will handle the applicative permissions.
Then we will use Keycloak to authenticate the client and authorize the access / access code, and the applicative part checks the permissions.
Problem
In addition to my first experiments, I surfed the Internet for a week, and I am surprised, because I thought it would be a very standard case. However, I found that nothing happens, so maybe I'm not looking for it right.
I found a lot of Spring / Spring Boot tutorials 1 on how to create a "simple authorization server". These are mainly SSO servers, and few manage permissions, with the exception of those mentioned in this SO answer 2 . I think we can handle it.
The real problem that I encountered, and that none of the trainees I found, handles the following:
How to integrate Keycloak on this authorization server?
I looked at the available Java adapters . They look fine when it comes to authentication, but I have not seen any hints on how to manage clients from a custom authorization server (i.e. administer an area).
I therefore assume that I should use the admin API . Is it right and is it good practice? I have not seen an adapter for this, so I suppose I should use the REST API.
I also wonder how should we integrate our users into the design? Should they be duplicated inside Keycloak? In this case, should I use the Keycloak admin API to enter data from the authorization server, or is there a better way?
Finally, did I miss another obvious point?
Sorry for the long post and many questions, but it all comes down to one question at the end:
What are the best practices when creating an authorization server using Keycloak as a backbone?
<sub> 1. Some examples: Spring OAuth2 Download Tutorial - Blog Post - Another Blog Post
<sub> 2. I mainly focus on the sample application provided by Spring Security OAuth