question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blazor PWA application does not reach the server for authentication due to service worker

See original GitHub issue

Hi

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:closed
  • Created 3 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Ricardoaraujo00commented, Dec 2, 2020

@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 👍

1reaction
guardrexcommented, Dec 2, 2020

@Ricardoaraujo00 … Add triple backtacks ☝️ … ``` … on the lines above and below that code to make it appear in the issue comment.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASP.NET Core Blazor Progressive Web Application (PWA)
Learn how to build a Blazor Progressive Web Application (PWA) that use modern browser features to behave like a desktop app.
Read more >
Blazor PWA using Negotiate authentification
My guess is that due to the PWA architecture, the service worker have something going on and think the user is still login....
Read more >
Blazor WASM PWA — Adding a “New Update Available ...
When the server is available, the service worker will check if a new version of the application is available or not. It does...
Read more >
Service workers - web.dev
Service workers are a fundamental part of a PWA. They enable fast loading (regardless of the network), offline access, push notifications, and other ......
Read more >
ASP.NET Core Series: PWA's with Blazor - YouTube
Since Blazor WebAssembly is a standards-based client-side web app ... a PWA with Blazor [07:38] - Exploring the manifest and service worker ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found