gpt4 book ai didi

c# - IdentityServer4 调试消息 AuthenticationScheme : "idsrv" was not authenticated

转载 作者:行者123 更新时间:2023-11-30 18:15:28 26 4
gpt4 key购买 nike

我使用 identityserver4 中间件创建了一个基本的核心应用程序。我已经在数据库中设置了资源和客户端。我还添加了用于签名消息的自签名证书。 IdentityServer4 似乎运行正常,但我看到一条困扰我的调试消息...

AuthenticationScheme: "idsrv" was not authenticated.

我只在我的身份服务器中创建了一个流 (client_credentials)。有谁知道我为什么会看到这条消息?

为了获得正确的响应,我在下面添加了 Startup.cs。

public static IConfigurationRoot Configuration { get; set; }

public Startup(IHostingEnvironment env)
{
// Setup and build the configuraton.
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json")
.AddJsonFile("appsettings.json");

Configuration = builder.Build();

// Setup and create the logger.
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo
.MSSqlServer(
Configuration["Serilog:ConnectionString"],
Configuration["Serilog:TableName"],
Serilog.Events.LogEventLevel.Debug,
autoCreateSqlTable: true)
.CreateLogger();
}

public void ConfigureServices(IServiceCollection services)
{
// Add serilog to the pipeline as the logging service.
services.AddLogging(loggingBuilder =>
loggingBuilder.AddSerilog(dispose: true));

// Add the configuration to the pipeline.
services.AddSingleton(Configuration);

// Add MVC to the pipeline.
services.AddMvc();

// Add the identity server db context to the pipeline.
services.AddDbContext<IdentityServerCoreDbContext>(options => options.UseSqlServer(
Configuration.GetConnectionString("IdentityServerCore")));

// Add our identity server stores and server to the pipeline.
services.AddTransient<IClientStore, ClientStore>();
services.AddTransient<IResourceStore, ResourceStore>();

services.AddIdentityServer()
.AddSigningCredential(Configuration["Certificate:Name"])
.AddResourceStore<ResourceStore>()
.AddClientStore<ClientStore>();
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
if (env.IsDevelopment())
app.UseDeveloperExceptionPage();

app.UseIdentityServer();

app.UseStaticFiles();

app.UseMvcWithDefaultRoute();
}

最佳答案

将以下行添加到“Startup.cs”中的“ConfigureServices”

services.AddMvcCore().AddAuthorization().AddJsonFormatters();
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.Authority = authority;
options.Audience = audience;
options.RequireHttpsMetadata = false;
});
services.AddCors();

然后将以下内容添加到“Startup.cs”中的“Configure”

app.UseCors(builder => builder.AllowAnyHeader()
.AllowAnyMethod()
.AllowAnyOrigin()
.AllowCredentials());

到 Startup.cs 中的“Configure”方法

尝试验证。

如果不起作用,请将您的 [Authorize] 修改为 [Authorize(AuthenticationSchemes = "Bearer"]

关于c# - IdentityServer4 调试消息 AuthenticationScheme : "idsrv" was not authenticated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48246335/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com