Is your feature request related to a problem? Please describe.
I am currently writing a Xamarin mobile app and a Blazor web app and attempting to share the backend of the two applications. Our web server uses the B2C authentication and was really easy to setup with Xamarin. I thought that i could try to use this library with Blazor since its now a part of the .net core family but it did not work as planned :(
Describe the solution you'd like
I would like to be able to use the C# Msal library to handle token authentication.
Describe alternatives you've considered
I know that I can use the Msal.js library from blazor to accomplish this task so i'm not blocked by this, I just thought it would be nice to use the C# .net standard library.
Additional context
The first issue i ran into was HttpClientHandler is not supported in the HttpClientFactory. I believe Blazor uses BrowserHttpMessageHandler instead of HttpClientFactory. I also ran into linking issues when trying to build the project when referencing the Msal library.
I think Blazor is a really cool technology and would love to see this library be able to be fill the needs of handing the authentication with Azure AD.
@dwightbennett. What is your scenario? Is it a Web app using Blazor calling a Web API?
Or a Web API calling a downstream web api?
Hi @jmprieur My scenario is a client side Blazor app calling a Web API.
@dwightbennett : Can you pls. share a bit more of your code and how you are using the factory? In the call to MSAL .NET you specify and object of type IMsalHttpClientFactory.
Did you create your own class? See e.g. https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/HttpClient
Not sure exactly where/how this is failing however if you have a sample that would be great.
Not sure which limitations WebAssembly has, however it's very likely that the http stack is a bit different and thus something has to bridge that. Perhaps netcore/blazor already has functionality for this?
A few related links for those trying to catch up on blazor:
https://devblogs.microsoft.com/aspnet/blazor-now-in-official-preview/
https://dotnet.microsoft.com/apps/aspnet/web-apps/client
https://github.com/aspnet/Blazor
Thanks @henrik-me for the suggestion. I added the WithHttpClientFactory method to the builder and implemented the factory for blazor. The next error I received was platform not supported. I will strip down my code to bear bones and try to get you an example project posted tonight or tomorrow morning.
@henrik-me I created a repo of a really simple blazor app with a login button that makes a call to login interactively. BlazorMsal You will need to add in client/application id, redirect uri, and authority in the StartUp.cs for the page to load. You can then see it hits the error found here WebUIFactory. Hope this helps.
@dwightbennett : thanks. We will take a closer look. Not sure right now on the actual timeline but hoping we can at least get a first glance at this in the next few weeks.
CC: @jmprieur
This is the last hurdle for me to propose a new Blazor client solution instead of our current vue.js implementation. @henrik-me / @jmprieur , any estimated idea when this scenario will be addressed or a roadmap?
@Matthewsre : we cannot prioritize this at the moment, and I did not even have time to look at what the experience is. If anybody in the community have time and ernergy to provide a PR (with unit tests), we'd certainly consider it.
Hi,
If you are in Blazor WebAssembly probably you are better off integrating with MSAL.js
I have an example here
https://github.com/cradle77/Blazor.Msal
It supports both the login flow and the access token acquisition, either in Popup or Redirect mode.
I鈥檓 building a NuGet package out of it to simplify the task in the meanwhile that an official solution becomes available.
/cc @jmprieur
@Matthewsre Did you ever find a way of making this work? I'm in the same boat.
We are currently discussing with the Blazor team on how we should best integrate. At the moment we are exploring msal.js . @DarylThayil
As far as I know this scenario is now supported through the use of Microsoft.Identity.Web https://github.com/AzureAD/microsoft-identity-web
Most helpful comment
@henrik-me I created a repo of a really simple blazor app with a login button that makes a call to login interactively. BlazorMsal You will need to add in client/application id, redirect uri, and authority in the StartUp.cs for the page to load. You can then see it hits the error found here WebUIFactory. Hope this helps.