Blazor PWA application does not reach the server for authentication due to service worker
See original GitHub issueHi
I’ve made a blazor wasm application, aspnet core hosted, with google authentication and custom AuthenticationStateProvider. When i try to create the same application from scratch but selecting Progressive Web App upon project creation, i’m not able to authenticate users. I’ve replicated the situation by building again a simple blazor wasm app with google authentication and custom AuthenticationStateProvider and again the exact same steps on the PWA version. It doesn’t work! In this documentation is missing what we are supposed to change in PWA application to be able to login with identity providers.
Debug: I see that the redirection from “user/signin” back to “/” is not working, it stays in address “user-signin” and in the log on visual studio there’s a error message saying: “Microsoft.AspNetCore.Authorization.DefaultAuthorizationService[2] Authorization failed.” In the network tab i see the navigation to “user/signin” and at the end, when trying to retrieve the user, the data for “/user” is retrieved from the service worker. In fact the “user/signin” is also served by the service worker. No wonder that the application doesn’t logs users. It cant reach the server. I cant understand why this happens but the documentation should state what are the adaptations we should do on the PWA scenario to keep the login working…
Thanks
cc: @guardrex Original issue: https://github.com/dotnet/AspNetCore.Docs/issues/20742
[Enter feedback h
Describe the bug
On clicking the login button i’m redirected to google for login. After selecting my account i’m redirected back to application with the google redirect url i’ve set in the google authentication service being displayed on the address bar, and the page displaying that nothing could be found at that address. That address is supposed to be consumed by the Microsoft.AspNetCore.Authentication.Google library on the server side but seems it gets trapped on frontEnd…
To Reproduce
Repo with the PWA version that is exactly the same as the other one except. The only difference is that this one was created with PWA option checked upon project creation: https://github.com/Ricardoaraujo00/BlazorApp3
Steve Sanderson solution that doesn’t work here
Exceptions (if any)
Further technical details
- ASP.NET Core version
- Include the output of
dotnet --info
- The IDE (VS / VS Code/ VS4Mac) you’re running on, and it’s version
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (6 by maintainers)
@guardrex i’ve found out how to do a PR to that documentation(i didn’t knew) but i think i won’t be able to use the proper language to explain the issue. I’m even running through a fog trying making this authentication, relying in tutorials and almost just following allong. So, in this situation when i’m using a custom authentication state provider to authenticate the user on the aspnet core backend using Microsoft.AspNetCore.Authentication.Google, i must ensure to have three adresses excluded from the service worker cache(?), which are those ones that i stated, being the last one, as far as i can tell, related to the google authentication nuget package. Have a nice vacation 👍
@Ricardoaraujo00 … Add triple backtacks ☝️ … ``` … on the lines above and below that code to make it appear in the issue comment.