I am currently implementing a system with Spring Boot as a resource server and Keycloak as an authorization server. I want to be able to create different roles for users but that should happen automatically, so no admin that is managing the Keycloak backend for this matter.
I have read about the Keycloak admin api but I am very unsure about this approach because it would mean storing login credentials in my resource server, which is not best practice at all, I think. So I want to store (business context) roles in the resource server but without implementing my own authorization approach for each endpoint. I want to be able to use the roles stored in the resource server with spring security for instance the hasRole() method but also all the other functionallity that is already being used by the OPEN ID authenication that hands over the roles from the authorization server.
So how would I go about this? Is there maybe a secure way to update user roles in the authorization server from the resource server? That would seem unlikely to me because (though not in my case) the authorization server might not be owned by the resource owner.
Or as another approach is it possible to fuse the roles handed to Spring Boot from keycloak and the roles stored in the resource server database and look them up after authenticating a user via keycloak?
I would be very glad about some code snippets but pointers to tutorials explaining the topic are just as appreciated.