Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle CORS Requests with Keycloak's "allowed-origins" claim like the keycloak adapter (now deprecated) #202

Open
ulk200 opened this issue Apr 4, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@ulk200
Copy link

ulk200 commented Apr 4, 2024

I would like to mimic the behaviour of the adapter that was maintained by the keycloak team, but that is now deprecated.
In class org.keycloak.adapters.AuthenticatedActionsHandler they used to read the allowed-origins claim and validate the Origin header of the HTTP request.

This claim is populated with the urls that are configured on the client, in the Admin Console : Clients -> #the client# -> Settings -> Web Origins

A nice feature is that when we set this form field with a plus sign + every valid redirect URI is also a valid web-origin that is copied in the token.

It seems that configuring cors with spring's CorsConfigurationSource is not dynamic enough to read from the token with each request.
What would be the cleanest way of doing it ?

Thanks

@ulk200 ulk200 added the enhancement New feature or request label Apr 4, 2024
@ulk200 ulk200 changed the title Handle CORS Requets with Keycloak's "allowed-origins" claim like the keycloak's adapter (now deprecated) Handle CORS Requests with Keycloak's "allowed-origins" claim like the keycloak adapter (now deprecated) Apr 4, 2024
@ch4mpy
Copy link
Owner

ch4mpy commented Apr 4, 2024

Hi @ulk200 and thanks for reaching out.

allowed-origins is a private claim. If other authorization servers were providing with equivalents, it would probably in other claims. In such a case, it could be worth to implement something similar to how authorities mapping is done (expose some configuration property accepting a JSON path to allowed origins claim). But I don't know any other provider exposing the origins it allows in claims, reason why I'm not quite inclined to add such a feature to spring-addons-starter-oidc.

However, your use-case is interesting and I'll try to put together the Java configuration to add (might take a few days to find the time for that).

@ulk200
Copy link
Author

ulk200 commented Apr 5, 2024

Yes a code sample or a tutorial would be enough since this is not standard. Your project always comes along when searching for a replacement for the adapters that the Keycloak team used to maintain, so i think it's an ideal place to find everything that can permit to fully replace it.
Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants