-
Notifications
You must be signed in to change notification settings - Fork 7
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
How to configure the library with microfrontends? #32
Comments
Hello @alanmatiasdev, I know that we use oidc-spa at Insee in microfronted setups but I never used microfronted myself. |
I made this small project to try to exemplify the issue, but I couldn't reproduce the error that is notified, however, it reproduces the issue of multiple states in local storage (is this expected behavior?). This project simulates an application of a real case that I have. If you try to run it and encounter any difficulties, please let me know. https://github.com/alanmatiasdev/react-mfr-oidc-example I'm trying to reproduce the initial behavior: when opening a new tab, it apparently can't read the state of the local storage and returns the error above. Update: I noticed that when opening a new tab, it searches for a state that does not exist in the local storage and this gives me the error mentioned above. |
@garronej I managed to resolve the issue of the error mentioned above (regarding opening new tabs) by changing the userStore from sessionStorage to localStorage. I made the change because sessionStorage does not share stored data between tabs even if a new tab is from the same source. Would this be a bad practice in any way or can we implement this possibility in the library? Lines 363 to 388 in a06808e
However the multiple states still remain and I believe it is related to having multiple instances of the lib on the page. |
First off, thank you for taking the time to investigate this so thoroughly.
Unfortunately, this isn’t ideal. The whole point of opening an iframe in the background and getting the auth server to redirect to Just to make sure we’re on the same page: I don’t believe there’s a known issue here, as we can restore the session using silent SSO. Can you confirm that you’re unable to reproduce any issues or suspicious behavior with the demo apps, like the TanStack Router demo app?
That’s concerning. You should have at most two session storage entries—something isn’t behaving as expected. I had some trouble running your demo repo: Could you update it to use my public Keycloak instance, which I use for my test project? You can check out the example here: This would make it easier for me, so we don’t have to spin up a Keycloak Docker container for testing, and we can rule out any issue related to a specific Keycloak configuration. I don’t have much experience with microfrontends, but my colleague @ddecrulle is quite knowledgeable in that area. If you can set up a straightforward reproduction path, there’s a good chance we’ll be able to figure it out. By the way, what brought you to this library? I’m curious since it still has a relatively small user base, and I’d love to know what convinced you to give it a try. |
I will test and return with feedback.
Yes, of course. I updated the repository https://github.com/alanmatiasdev/react-mfr-oidc-example
I have been using Keycloakify for some time now, since implementing oidc-spa. I tested it in a development environment and, based on my analysis, I found the library to be more stable than the implementation we had. I chose to adopt it due to its simplicity of implementation. |
It is working correctly. I believe this has something to do with the microfrontends configuration. |
Thanks for the report, I'm having the same issue as @garronej : |
The issue occurred because I had something running on port 5173, and the monorepo doesn’t handle port changes well.I can reproduce now. |
Can you guys give a try with |
Could we include the possibility for the user to change the storage, perhaps marking it as unsafe?
I will try and get back to you. |
I would prefer not to. While it's rellevent to be offered as an option for React Native or Electron desktop app, OIDC-SPA is specifically designed for web application.
Did you had a chance to try it? There's good chances that the problem has been fixed in the latest release of oidc-spa. |
I haven't had time to check yet. I should check by the end of the week and get back to you. |
The multi-state behavior still remains in v5.4.0. I notice it occurs mainly when a new tab is opened. @ddecrulle could you tell me if, in my microfrontend scenario, it would be an alternative to remove the libraries from the react application and leave it in the root (the orchestrator with the single-spa). |
This approach can work but comes with significant limitations. You cannot secure anything in the remote application, and if you need tokens, it will be tricky to manage them, which will significantly impact the developer experience. Additionally, you will create implicit dependencies between the host and the remote, which could lead to maintenance challenges. I will try to understand why there is multistate. Maybe it's related to the oidc-spa_config_hash |
The issue you're experiencing is caused by a bug in Here is a detailed explanation of the behavior: When calling This, in turn, calls the We will try to fix this. |
This is something that is important to us as well. I'll adress it as soon I have the time. |
Hello @alanmatiasdev, I've finaly got around fixing the problem pointed out by @ddecrulle. Let us know if |
Thanks for the quick response @garronej. I will test again. |
Hello, can you confirme that the problem is solved so I can close ? |
The problem of multiple entries in local storage has been resolved, but this has certainly been happening frequently. When opening a new application tab, it does not recognize the user's authentication status. I have not tested it outside the context of microfrontends. Screencast.from.27-10-2024.12.49.24.webm |
Great, the issue with multiple entries is fixed. I don’t understand the remaining issue. I’ve tested it:
You can find more documentation here. To clarify:
|
Thanks @ddecrulle, If you can provide a reproduction path using the creadentials of our Keycloak we can address it... |
I have a set of micro frontends divided into a single page layout: header, content. It turns out that, in general, the platform displays the header and content at once. Since I need user information in both contexts, I include the library for both applications. This causes the library to create different states in the browser's local storage and when opening a new browser tab I get the message that no state was found in the browser. Is there any guidance for this scenario?
OIDC initialization error of type "unknown": No matching state found in storage
The text was updated successfully, but these errors were encountered: