.NET 8 Blazor Interactive WebAssembly HttpClient and Identity issues

279 Views Asked by At

This is how I created the project

Solution creation

So far I have:

  • Added Roles to the project, and they are working on FE and BE, e.g. I have added a specific user to a role, and content is rendered on the FE if the user has a role, and the BE endpoint can be accessed directly if the user has role = request is sent by the browser and this is OK.

My problem is HttpClient or HttpClientFactory registration, what I have done so far:

  • I have added Controllers to the BE project
  • I have added HttpClient service registration (but this time it has to be added to BE - due to interactivity...)

My next step is to use a generic solution for HTTP communication e.g. in my case I have written my own, but let's take refit as an example, how do I register refit and use it in FE?

The problem is, on the client side, you can't just register it as before due to the interactivity since it has to be on BE

builder.Services.AddHttpClient("WebAPI", client =>
    client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)

Now what? My scenario is very complex, and this is what I want to achieve:

  • I want to have BE API
  • I want to have FE WebAssembly
  • I want to have a new Identity implementation that is written in Razor components
  • I want to have Generic HttpClient implementation with HttpClientFactory on FE in order to access data from BE
  • I want to preserve authentication and authorization and let users access only parts for which they have Roles, but this has to be included in the HttpClient too
  • Later on, I want to add more applications e.g. .NET MAUI to consume my existing API.

In the end, I did read a lot about render modes and everything else, and I find it very hard to achieve my goal with the current mindset, any suggestions and concrete answers will be very appreciated.

0

There are 0 best solutions below