Skip to content

WEB-267 Remove tenant identifier for OAuth token requests #2580

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

sidhantgoel
Copy link

@sidhantgoel sidhantgoel commented Aug 7, 2025

Description

The problem is Fineract-Platform-TenantId header is rejected by CORS policy on the endpoints exposed by keycloak.
This is a fix to remove this header from the requests to keycloack oauth server.

Related issues and discussion

WEB-267

Screenshots, if any

Checklist

Please make sure these boxes are checked before submitting your pull request - thanks!

  • If you have multiple commits please combine them into one commit by squashing them.

  • Read and understood the contribution guidelines at web-app/.github/CONTRIBUTING.md.

Copy link
Collaborator

@steinwinde steinwinde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create a Jira ticket, assign it to you, update its status and reference it in your PR description: https://mifosforge.jira.com/jira/software/c/projects/WEB/list?direction=DESC&sortBy=key This is a requirement for PRs. Thank you for contributing!

@sidhantgoel sidhantgoel changed the title Fix: Remove tenant identifier for OAuth token requests WEB-267 Remove tenant identifier for OAuth token requests Aug 7, 2025
@sidhantgoel
Copy link
Author

@steinwinde Thanks for the update, please let me know if it looks ok now?

@sidhantgoel sidhantgoel requested a review from steinwinde August 7, 2025 10:56
@IOhacker
Copy link
Contributor

@sidhantgoel I think this change oveheads the validation of any OIDC tool. Keycloak is a reference but there are others. Which is the benefit of removing the fineract tenant id header?

@sidhantgoel
Copy link
Author

sidhantgoel commented Aug 11, 2025

@IOhacker In my opinion, we shouldn't send headers to the OIDC or any other server if they're not expected or used. Most likely, the provider will reject them. While CORS doesn't inherently block specific headers, the provider defines which headers are allowed. If a header isn't included in that list, the browser will block the request. Is there any downside to simply removing it?

@IOhacker
Copy link
Contributor

IOhacker commented Aug 11, 2025 via email

@sidhantgoel
Copy link
Author

sidhantgoel commented Aug 11, 2025

@IOhacker CORS applies to API calls made through the browser—it's necessary for Fineract, but not for OAuth. So, there's no point in sending it with OAuth requests. I've only removed it for OAuth, not for Fineract. Also, just because it works with one auth provider doesn't guarantee it will work with others. We should adhere to the OIDC specification, and this header isn't defined there.

Just to clarify, this change won't remove the header from any Fineract requests—even when OAuth is enabled. It only removes the header from requests sent to the OAuth server by the web app.

@IOhacker
Copy link
Contributor

IOhacker commented Aug 11, 2025 via email

@IOhacker
Copy link
Contributor

Also the console.log must be removed.

@sidhantgoel
Copy link
Author

sidhantgoel commented Aug 11, 2025

Sure will remove console.log but this header is part of token request and hence it is not working with keyclock. Please see the screenshot captured from the url shared.
Screenshot 2025-08-11 at 12 06 42 PM

@IOhacker
Copy link
Contributor

I dont see any error in the screen shared. You got a 200 which means that the flow is working. Even the screen shows the next api calls. This ticket is not showing any previous error.

@IOhacker
Copy link
Contributor

IOhacker commented Aug 11, 2025

Here is the video of the instance working with all the endpoints (login, logout, refresh token) https://youtu.be/xXCCPsxqvR4 son then I don't think this change must be merged.

@sidhantgoel
Copy link
Author

t's not working with Keycloak. I'm not saying the instance itself is broken—I shared a screenshot to show that the header is indeed being sent to the OIDC server.

@sidhantgoel
Copy link
Author

And if you're saying it should only work with your configuration and that Keycloak or other providers don't need to be supported—well, so be it 😄

@IOhacker
Copy link
Contributor

IOhacker commented Aug 11, 2025

This is using Keycloak. Please take some time to read the video description and my previous comments. Until now this change is not approved by me.

@sidhantgoel
Copy link
Author

Can you tell me which version ov Keycloak it is because it is definetly not working with latest version?

@sidhantgoel
Copy link
Author

Please read the issue already raised with Keycloak keycloak/keycloak#12682

@IOhacker
Copy link
Contributor

It is using the latest Keycloak version 26.3.2-0

The issue is at another point. Please check the image.

image

I insist this code change is not the solution.

@sidhantgoel
Copy link
Author

sidhantgoel commented Aug 11, 2025

Can you point me towards the right fix? The header is being sent from the interceptor wich is common for oauth and fineract requests, should we not use interceptor in case of oauth requests?

@IOhacker
Copy link
Contributor

Take you time to debug it. But this code is not the solution.

@sidhantgoel
Copy link
Author

I fixed the issue that you have shown in the screenshot, the CORS issue came after that.

@IOhacker
Copy link
Contributor

IOhacker commented Aug 11, 2025 via email

@sidhantgoel
Copy link
Author

The issue here is that we're trying to augment HttpClient, which is provided via provideHttpClient. Because of this, the provider configuration we set up for creating HttpService doesn't take effect—HttpClient is always injected instead of HttpService, and HttpClient doesn't have the disableApiPrefix method.

Augmenting in this case either won’t work at all or would require a lot of hacks and/or copying code from the original module that provides HttpClient, which I don't recommend.

I didn’t commit that code because I simply commented out the disableApiPrefix call. The handling for full URLs is already covered by the ApiPrefixInterceptor, and we can always pass a full URL when we don’t want the API prefix added.

If required I can commit that code also.

@IOhacker
Copy link
Contributor

IOhacker commented Aug 11, 2025 via email

@sidhantgoel
Copy link
Author

Screen.Recording.2025-08-11.at.2.48.33.PM.mov

Here is the screen recording

@IOhacker
Copy link
Contributor

IOhacker commented Aug 11, 2025 via email

@sidhantgoel
Copy link
Author

Screen.Recording.2025-08-11.at.3.05.07.PM.mov

Here you go

@IOhacker
Copy link
Contributor

IOhacker commented Aug 11, 2025 via email

@sidhantgoel
Copy link
Author

done, please check

environment.oauth.enabled &&
(request.url.includes(`${environment.oauth.serverUrl}/token`) ||
request.url.includes(`${environment.oauth.serverUrl}/logout`))
) {
Copy link
Contributor

@IOhacker IOhacker Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes on this file are not required. Please remove from the PR

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

Successfully merging this pull request may close these issues.

3 participants