Hosted Blazor WASM and Azure AD B2C with Microsoft.Identity.Web

Viewed 54

I am trying to integrate AD B2C in a hosted Blazor WASM application. I need to intercept the creation of new user in order to populate some entries in the database and also redirect the user to a configuration page.

Some previous posts suggest of hooking an event handler to the authentication configuration, as in

services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
                .AddMicrosoftIdentityWebApi(JwtBearerOptions =>
                {
                    JwtBearerOptions.Events ??= new JwtBearerEvents();
                    JwtBearerOptions.Events.OnTokenValidated += OnTokenValidatedCallbackFunc;
                },
                configureMicrosoftIdentityOptions =>
                {
                    Configuration.Bind("AzureAdB2C", configureMicrosoftIdentityOptions);
                });

However the event is not triggered. The only event that seems to be triggered is OnMessageReceived. However, that is not useful in my case because I need to access the claims, and the Principal does not seems to be defined if I examine the MessageReceivedContext (Principal is always null).

Any help is greatly appreciated! Thank you in advance.

0 Answers
Related