在阅读了Microsoft的identity文档后,似乎为了让他们的示例按书面形式工作,需要使用identity。呼叫
AddIdentity
和
AddDefaultTokenProviders
配置默认值以下代码将或多或少按照我的要求执行(JWT除外)
//configure identity
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
//configure other providers
var authSection = Configuration.GetSection("Authentication");
var authBuilder=services.AddAuthentication()
.AddGoogle(options => authSection.Bind("GooglePlus", options))
.AddAzureAd(options => authSection.Bind("AzureAd", options));
医生说:
注:
呼叫
额外性
配置默认方案设置。这个
AddAuthentication(string defaultScheme)
重载设置
DefaultScheme
所有物而且
AddAuthentication(Action<AuthenticationOptions> configureOptions)
重载仅设置显式设置的属性。添加多个身份验证提供程序时,这些重载中的任何一个都只应调用一次。对它的后续调用可能会覆盖任何以前配置的
AuthenticationOptions
属性。