I have a Blazor Server Side app configured with B2C auth. This app will call a webapi to do any of the data exchanges with my service. B2C auth works fine, and straight from template the config B2C auth is:
services.AddAuthentication(AzureADB2CDefaults.AuthenticationScheme)
.AddAzureADB2C(options => { Configuration.Bind("AzureAdB2C", options); });
The claims only has the claims I'm returning from my signin policy, without any access tokens I can use for auth on behalf to my Web api (Also secured with same B2C tenant).
I've read about 100 different docs, but it seems that nothing makes sense in the context of blazor. Is there anyone that has done this before that could shed some light?
First prize would be to request an access token once the user auths to B2C the first time, and then keep the token in cache to use in the blazor app for any api calls while the session / browser is open or the access token is valid.
It seems that this is the right path: https://github.com/Azure-Samples/active-directory-b2c-dotnet-webapp-and-webapi/blob/master/TaskWebApp/Controllers/TasksController.cs but what I'm not understanding is:
- Is this the right approach for Blazor?
- How can I trigger it to get the access token requested on auth of the user. It's unclear to me on how to override the B2C auth constructors.
- Could I add the access and refresh tokens in the claims of the current user so that I can work with the httpcontext objects within my app globally to get the tokens required to do my api call?
- The code in the doc above is of course in a controller. Would love to have this just form as part as the auth flow of the user.
- It seems like the configuration of B2C auth is now very templated... For example, where would I be able to customize the routes for auth? I'd like to rather direct the user to /auth or /login than /AzureB2C/Login (To obscure the obvious auth provider url. I know it shows up for the user in the address bar... but hey... Any help will be greatly appreciated that would be specific on how to handle this in Blazor Server Side.
Thanks!