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

Cookie example does not work for .Net 8 template because the state container does not instantiate in user scope #31899

Closed
kaleidocore opened this issue Feb 23, 2024 · 8 comments

Comments

@kaleidocore
Copy link

Description

This example does not seem to work with the .Net 8 Blazor template, i.e. when using the new type of server-interactive rendering.
The reason is that the root App component does not render in user-scope, but rather in some anonymous pre-render scope that you cannot disable. This causes the state container (TokenProvider service) to instantiate once for the App component while a different (user-scoped) instance is created for the consuming component.

Page URL

https://learn.microsoft.com/en-us/aspnet/core/blazor/security/server/additional-scenarios?preserve-view=true&view=aspnetcore-8.0#pass-tokens-to-a-server-side-blazor-app

Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/blazor/security/server/additional-scenarios.md

Document ID

c98be365-408d-7ee6-cb74-14c44d01b0b8

Article author

@guardrex

Copy link
Contributor

💘 Hello, February! Goodbye, New Year's resolutions! 😆

A green dinosaur 🦖 will be along shortly to assist. Stand-by ........

@guardrex
Copy link
Collaborator

Hello @kaleidocore ... This is a duplicate of #31691. Although I've pinged engineering for assistance with it, I haven't heard back yet.

I'll take two actions...

  1. I'll ping again offline (email) on Monday.
  2. I'll research further on my own and report back on the other issue. Keep an 👁️ on it for an update by Monday afternoon EST.

@github-project-automation github-project-automation bot moved this from Triage to Done in Blazor.Docs Feb 23, 2024
@guardrex
Copy link
Collaborator

One more thing ... depending on what ur trying to implement, take a look at our new article and samples for BWAs with OIDC at ...

https://learn.microsoft.com/en-us/aspnet/core/blazor/security/server/blazor-web-app-with-oidc?view=aspnetcore-8.0&pivots=without-bff-pattern

@kaleidocore
Copy link
Author

@guardrex Thanks for the very quick reply and suggestion! I was actually not trying to implement authentication but rather theming and localization, which are also based on cookies before first render to avoid FOUC. I did however (independently) discover the workaround suggested in the #31691 (comment) in the duplicate post. Sorry for the dupe!

@guardrex
Copy link
Collaborator

For managing localization in a BWA, see the PR that I just put up this morning, and my test app is linked there. Perhaps, it will help with your project.

#31894

@guardrex
Copy link
Collaborator

Re-opening for work now that we have knowledge of ...

https://github.com/javiercn/BlazorWebNonceService/

... via the PU issue.

I'll probably work this along with #31691 on the same PR. I hope to reach this work within the next few days.

@guardrex guardrex reopened this Feb 27, 2024
@github-project-automation github-project-automation bot moved this from Done to Triage in Blazor.Docs Feb 27, 2024
@guardrex guardrex moved this from Triage to 8.0 in Blazor.Docs Feb 27, 2024
@kaleidocore
Copy link
Author

Re-opening for work now that we have knowledge of ...

https://github.com/javiercn/BlazorWebNonceService/

Just FYI, the persist pattern also does not work in this case because the root component never re-renders in user-scope, or at all for that matter.

@guardrex
Copy link
Collaborator

There was no need for me to re-open this. The additional information applied to a different issue. The sample app has been updated for the nonce problem.

This will be tracked by #31691, and I hope that they'll get to it soon 🤞.

@github-project-automation github-project-automation bot moved this from 8.0 to Done in Blazor.Docs Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

3 participants