Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I generate a Keycloak user access token without password?

I have a legacy system that has an existing login mechanism - assume it is a custom method. We have another set of services that require an oauth2 access token and use keycloak for generating and verifying the tokens. After a user logs in we no longer have access to their password hence I can not use the password grant to get them an access token to our oauth based system. What are the recommended approaches to generate this access token. What I have looked into so far:

  • impersonation (token exchange)
  • custom keycloak userstore SPI that validates user with blank password
  • I guess using a client credential flow to generate a token that tries to match the users roles and attributes.

It seems to be a use case that is not well supported by oauth2?

like image 466
George Avatar asked Oct 17 '25 15:10

George


1 Answers

It seems to be a use case that is not well supported by oauth2?

Your use-case seems to match those defined in the OAuth 2.0 Token Exchange specification

One common use case for an STS (as alluded to in the previous section) is to allow a resource server A to make calls to a backend service C on behalf of the requesting user B.

For this approach, you will need to configure in the appropriate Keycloak realm your legacy system as Identity Provider. So that you create a trust-relationship between the legacy system and Keycloak. Afterwards, you can exchange the token coming from the legacy system (resulting from the user authentication) for a token of the aforementioned realm. Depending upon your setup you might need protocol mappers that map the legacy system roles to the roles in the Keycloak realm. All of this is assuming that your legacy system is to a certain extend Oauth2 compliant.

Otherwise, another approach is for your legacy system, to call a confidential client on Keycloak and pass along some claims (e.g., the user roles). This is assuming that your legacy system can securely store the client secret. All of this, of course, depends upon the concrete characteristics of your setup.

like image 127
dreamcrash Avatar answered Oct 21 '25 09:10

dreamcrash