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.

Consider re-designing the Blazor WASM authentication stack

See original GitHub issue

👋🏻

The Blazor WASM OIDC authentication stack was built around the oidc-client-js library. Sadly, this library is no longer supported and the GitHub repository was archived last year.

As I suspect the ASP.NET team will consider opting for a different solution at some point, I guess it’s a good opportunity to discuss the design of the authentication stack and suggest potential improvements.

Last month, I unveiled the OpenIddict client, a new OAuth 2.0/OIDC client designed with extreme flexibility in mind (so it can be used with the worst non-standard server providers the world can offer 😄). As part of the effort, I’d love to provide native Blazor integration. I worked on a prototype based on the existing Blazor 6.0 authentication APIs and it’s promising, but I believe there’s place for improvement.

One of the main points that could be improved is how things are currently layered: unlike ASP.NET Core’s authentication stack that offers specialized authentication handlers (cookies, OIDC, etc.), things are tightly coupled in the Blazor WASM world. More specifically, it would be great if the user persistence part (using local or session storage) was independent from the components handling the external authentication dance (in my case, OIDC). Something modeled after ASP.NET Core’s IAuthenticationHandler/IAuthenticationService abstractions would be excellent.

Is it something that could be done as part of 7.0?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:71
  • Comments:18 (10 by maintainers)

github_iconTop GitHub Comments

8reactions
kevinchaletcommented, Mar 22, 2022

Originally our auth system was implemented as a wrapper over JS libraries because they offered out of the box support for things like silent sign-in, etc. Given that the cookie changes have effectively killed most of those features, we are reconsidering our approach on this area.

Sadly, this led to an odd design: RemoteAuthenticationService aims at being an open/generic base implementation but it’s actually tied to oidc-client-js under the hood as AuthenticationService.ts is just a wrapper around it. Even things like storing or getting the current user identity are simple wrappers around oidc-client-js.

Replacing oidc-client.js is in our roadmap, that said, we are not looking at revamping the auth system with something as sophisticated as the auth system in ASP.NET Core.

I suggested that for one reason : ASP.NET Core’s authentication abstractions are battle-proven, extremely extensible and yet not insanely complex (they were inherited from Katana and got an overhaul as part of ASP.NET Core 2.0). So why would you reinvent the wheel? 😃

That said, we are considering what we do in this area, however in general we want to minimize as much as possible the number of primitives/complexity we ship in-box and enable people to integrate with our abstractions to tune auth to their needs.

Unlike ASP.NET Core - for which devs have written thousands of authentication handlers of all types - I personally haven’t seen many actual derived implementations of Microsoft.AspNetCore.Components.WebAssembly.Authentication, which makes me think the “enable people to integrate with our abstractions” part of the contract is not exactly fulfilled 😄

If you have concrete code snippets of what you are proposing I’m happy to move the conversation forward.

I don’t have specific snippets to share, but as I said in my OP, the main issue is how things are coupled. If at least the user persistence part was decoupled from the oidc-client-js, it would help a lot. Think of it as an equivalent of CookieAuthenticationHandler for Blazor (should I dare call that LocalStorageAuthenticationHandler or SessionStorageAuthenticationHandler?)

4reactions
kevinchaletcommented, Mar 22, 2022

(since the first post got already 5 👍🏻, I guess I’m not the only one interested in seeing improvements in this area 😃)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Safety of authentication configuration in Blazor WASM
I'm super new to authentication schemes but have been implementing some basic Authentication and Authorization within a Blazor WASM ...
Read more >
Securing Blazor WebAssembly Apps - Auth0 Community
Learn how to secure Blazor WebAssembly applications with Auth0. ... NET 8: Consider re-designing the Blazor WASM authentication stack ...
Read more >
Blazor | Build client web apps with C# | .NET
Blazor is a feature of ASP.NET for building interactive web UIs using C# instead of JavaScript. It's real .NET running in the browser...
Read more >
Introduction to Authentication with server-side Blazor
In this post, I'll show you how you can create a new server-side Blazor application with authentication enabled.
Read more >
How Microsoft Blazor Uses WebAssembly
Last week I introduced you to Blazor, Microsoft's web stack that eschews JavaScript and enables developers to use WebAssembly on the client ...
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