一种可能的解决方法是在Startup.cs中将OpenIdDict的配置属性设置为默认值。以下是示例代码:
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.AddDbContext(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity()
.AddEntityFrameworkStores()
.AddDefaultTokenProviders();
services.AddAuthentication(options =>
{
options.DefaultScheme = OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme;
options.DefaultSignInScheme = OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme;
})
.AddJwtBearer(options =>
{
options.Authority = Configuration["Authentication:JwtIssuer"];
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = false,
ValidateLifetime = true,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(Configuration["Authentication:JwtKey"])),
ClockSkew = TimeSpan.Zero
};
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
[...]
app.UseAuthentication();
app.UseAuthorization();
app.UseOpenIddict();
}
此外,还应该确保在项目文件中添加OpenIdDict的引用,如下所示:
如果问题仍然存在,请查看OpenIdDict和ASP.NET Core的文档,以获得更多的解决方案和支持。