-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Update section on passing tokens in Blazor Web Apps #31691
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
Comments
I just found this issue, so I'll just leave my two cents here. I tried applying this to my own blazor server 8 app. When adding a scoped TokenProvider service, the set value will not be handed over to the circuit. The value will initially be set during the prerender, but on the second oninitializedasync null. What did work was marking the service as singleton, though I'm not sure if this is the way the documentation intended it to be done. |
#31759 got closed, but let me share what worked for me, if helpful to patch the documentation or to others searching for solution to the issue: Capturing a cookie inline like this and then passing it as a Parameter to the Routes component where it's stored in the scoped provider seems to do the trick:
|
Another suggestion for that section of the documentation: Mixing OpenIdConnect in the example creates the impression that there might be some magic happening there, that alleviates the issue with the pre-rendering and the duplicated TokenProvider. A simple example with a cookie would have been simpler and to the point. |
@GStoynev wow that is a very easy solution 🤔. One other thing I found out yesterday is that the httpcontext is always available within a HttpClient implementation, wherever you inject it inside the circuit. Which is also what the documentation does, I believe. |
The product unit (PU) is working through their backlog to reach this issue and take a look at the section. I hope we'll have this sorted out no later than the end of next week (2/23). |
Still trying to get 👁️👁️ on this. I'll try to reach out to Stephen and Jeremy again on Monday. |
No 🎲🎲 .... That only addresses the nonce situation. Also, that sample doesn't match the approach that Stephen adopted for the BWA on dotnet/blazor-samples#240. |
@pmi24 Blazor authentication is really a complicated topic, especially now we have the |
Finally, I found someone noted InteractiveServer does valid for HttpContext and IHttpContextAccessor. The Microsoft website really confusion which state "IHttpContextAccessor]must be avoided with interactive rendering because there isn't a valid HttpContext available.". I think only the code that run at the client side will NOT valid for HttpContext like InteractiveClient or InteractiveAuto that after first initialization. |
Yes, by means of debugging I see that the same code gets run twice, in SSR. The first time HttpContext has value while in the second time it's null. So all in all, 'should be avoided' is correct. |
Update to "three projects." |
Description
Per our offline discussion, I'll see about implementing Halter's suggestion at Stephen's remarks fleshed out further for this.
Also see #35225.
Here's the LIVE section link that merely tells readers that this content is due to be updated ...
https://learn.microsoft.com/en-us/aspnet/core/blazor/security/server/additional-scenarios?view=aspnetcore-8.0#pass-tokens-to-a-server-side-blazor-app
What we have for Blazor Server is in the 7.0 version of the article ...
https://learn.microsoft.com/en-us/aspnet/core/blazor/security/server/additional-scenarios?view=aspnetcore-7.0#pass-tokens-to-a-server-side-blazor-app
Page URL
https://learn.microsoft.com/en-us/aspnet/core/blazor/security/server/additional-scenarios?view=aspnetcore-8.0
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
The text was updated successfully, but these errors were encountered: