【发布时间】:2018-07-24 19:32:17
【问题描述】:
我正在从 IdentityServer4 1.x 升级到 IdentityServer4 2.0,这也意味着我已经升级到 .Net core 2.0 我知道这次升级有很多重大变化我已经做过一次之前,但由于某种原因,我陷入了这个错误。
警告:IdentityServer4.Startup[0] 未设置默认身份验证方案。需要设置默认方案。
警告:IdentityServer4.Startup[0] 未设置默认身份验证方案。需要设置默认方案。
在我调用app.UseIdentityServer(); 后,错误出现在Configure
配置方法:
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
if (Debugger.IsAttached)
loggerFactory.AddConsole(Configuration);
else
loggerFactory.AddConsoleJson(Configuration);
InitializeDatabase(app);
// Stops microsoft from overwriting claim types to their proprietary ones
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
app.UseAuthentication();
app.UseCors(builder =>
builder.AllowAnyHeader()
.AllowAnyMethod()
.AllowAnyOrigin()
.AllowCredentials()
);
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedProto
});
app.UseDeveloperExceptionPage();
app.UseIdentityServer();
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
}
ConfigureServices 方法
public void ConfigureServices(IServiceCollection services)
{
var settingsSetup = Configuration.GetSection("Settings").Get<Settings>();
settingsSetup.XenaConnectionUrl = Configuration["XenaPath"];
services.AddSingleton(settingsSetup);
var idsConnectionString = Configuration.GetConnectionString("XenaIdentityConnection");
var xenaConnectionString = Configuration.GetConnectionString("XenaConnection");
var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;
services.AddDbContext<UserDbContext>(builder =>
builder.UseSqlServer(xenaConnectionString));
services.AddCors();
services.AddMvc();
services.TryAddScoped<UserManager, UserManager>();
services.TryAddScoped<SignInManager, SignInManager>();
services.TryAddSingleton(new XenaClient(Configuration));
services.AddTransient<Services.IClaimsService, XenaClaimsService>();
services.AddTransient<IProfileService, ProfileService>();
// Sms service setup
services.Configure<SmsOptions>(Configuration.GetSection("SmsOptions"));
services.AddTransient<ISMSService, SMSService>();
services.AddTransient<IResourceOwnerPasswordValidator, PasswordValidator>();
services.AddIdentityServer()
.AddSigningCredential(LoadCertificate())
// this adds the config data from DB (clients, resources)
.AddConfigurationStore(options =>
{
options.ConfigureDbContext = builder =>
builder.UseSqlServer(idsConnectionString,
sql => sql.MigrationsAssembly(migrationsAssembly));
})
// this adds the operational data from DB (codes, tokens, consents)
.AddOperationalStore(options =>
{
options.ConfigureDbContext = builder =>
builder.UseSqlServer(idsConnectionString,
sql => sql.MigrationsAssembly(migrationsAssembly));
})
.AddProfileService<ProfileService>();
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = IdentityConstants.ApplicationScheme;
options.DefaultChallengeScheme = IdentityConstants.ApplicationScheme;
});
services.AddAuthorization(options =>
{
options.AddPolicy("Supporter", policy => policy.RequireClaim("supporter"));
});
}
我正在设置 DefaultAuthenticateScheme,所以我无法真正弄清楚问题所在。我已经在源代码中进行了挖掘,它似乎与验证有关我显然没有添加任何东西,但我无法弄清楚它是什么source
【问题讨论】:
-
什么是
IdentityConstants.ApplicationScheme?
标签: c# oauth .net-core identityserver4