How to add OnTokenValidated event handler when using AD B2C?

前端 未结 1 1785
礼貌的吻别
礼貌的吻别 2021-01-21 08:09

I am using Azure B2C in a ASP.NET Core 3 application, which is working perfectly. I use the following code in Startup:

services.AddAuthentication(AzureADB2CDefa         


        
相关标签:
1条回答
  • 2021-01-21 08:50

    I found my answer, by searching for ["Events.OnTokenValidated" AzureAdB2C] in github, and assembled the following for my case:

    // My existing code in Startup:
    services.AddAuthentication(AzureADB2CDefaults.AuthenticationScheme)
            .AddAzureADB2C(options => Configuration.Bind("AzureAdB2C", options));
    
    // My added code to handle the OnTokenValidated event
    services.Configure<OpenIdConnectOptions>(AzureADB2CDefaults.OpenIdScheme, options =>
    {
        var onTokenValidated = options.Events.OnTokenValidated;
        options.Events.OnTokenValidated = context =>
        {
            onTokenValidated?.Invoke(context);
            // My custom handler goes below:
    
    0 讨论(0)
提交回复
热议问题