KunLi-4284 avatar image
0 Votes"
KunLi-4284 asked MarileeTurscak-MSFT commented

OptionsConfigurationServiceCollectionExtensions add options


I would like to change the OnTokenValidated event in authentication.
But do not know how to use the BinderOptions in OptionsConfigurationServiceCollectionExtensions.

 public void ConfigureServices(IServiceCollection services)
     services.Configure<CookiePolicyOptions>(options =>
         // This lambda determines whether user consent for non-essential cookies is needed for a given request.
         options.CheckConsentNeeded = context => true;
         options.MinimumSameSitePolicy = SameSiteMode.Unspecified;
         // Handling SameSite cookie according to
     // Configuration to sign-in users with Azure AD B2C
     services.AddMicrosoftIdentityWebAppAuthentication(Configuration, "AzureAdB2C");
     //Configuring appsettings section AzureAdB2C, into IOptions

Say, if I want to change the sample code above to this one. Looks like I can't directly do this.

  services.Configure<OpenIdConnectOptions>(Configuration.GetSection("AzureAdB2C"), options => {
              options.TokenValidationParameters.RoleClaimType = "roles";
              options.Events.OnTokenValidated = (ctx) =>
                 var redirectUri = new Uri(ctx.Properties.RedirectUri, UriKind.RelativeOrAbsolute);
                 if (redirectUri.IsAbsoluteUri)
                     ctx.Properties.RedirectUri = redirectUri.PathAndQuery;

                 var claimsIdentity = ctx.Principal?.Identity as ClaimsIdentity;
                 claimsIdentity?.AddClaim(new Claim(ClaimTypes.Role, "Admins"));
                 return Task.FromResult(0);
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Could you please provide more details around which sample you are following, which error you are receiving, and which objective you would like to achieve? There is an example here of overriding OnTokenValidated. t

0 Votes 0 ·

0 Answers