在ASP.NET Core MVC Web应用程序中,我们需要使用JWT令牌同时支持Azure B2C用户和其他外部用户。
基本上,如果请求中包含JWT令牌,我们想使用JWT进行身份验证,或者我们想使用Azure B2C进行身份验证。
在启动类中,我们具有以下身份验证代码:
services.AddAuthentication(options =>
{
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = Configuration["AzureAdB2CSignUpSignInPolicyId"];
})
.AddOpenIdConnect(Configuration["AzureAdB2CSignInPolicyId"], options => SetOptionsForOpenIdConnectPolicy(Configuration["AzureAdB2CSignInPolicyId"], options, Configuration))
.AddOpenIdConnect(Configuration["AzureAdB2CSignUpSignInPolicyId"], options => SetOptionsForOpenIdConnectPolicy(Configuration["AzureAdB2CSignUpSignInPolicyId"], options, Configuration))
.AddCookie();
由于该代码仅在应用程序启动时运行一次,我们如何才能有条件地对用户进行身份验证(JWT与B2C)?有人成功做到了吗?