IdentityServer4出现“idsrv未认证”调试消息的原因求助
关于 AuthenticationScheme: "idsrv" was not authenticated 调试消息的解释
别担心,这条调试消息在你使用client_credentials流程的场景下是完全正常的,不会影响你的IdentityServer功能运行,下面给你拆解原因:
idsrv这个认证Scheme是IdentityServer用于处理用户身份认证的(比如授权码模式、密码模式里的用户登录环节),但client_credentials模式是纯客户端认证,全程没有用户参与,自然不存在用户身份需要认证的情况。- 当IdentityServer处理请求时,内部会尝试触发用户认证流程,但因为你的场景里根本不需要用户身份,也没有配置任何用户认证相关的服务(比如ASP.NET Core Identity),所以这个认证尝试会失败,进而输出这条调试级别的日志。
从你的Startup代码来看,你确实只配置了客户端存储、资源存储和签名证书,没有添加用户身份认证的相关逻辑,这完全符合client_credentials模式的需求,所以这个消息只是个“无害的提示”而已。
如果觉得这条日志太烦,你可以调整Serilog的日志级别,把MinimumLevel.Debug()改成MinimumLevel.Information(),这样就不会再看到这条调试消息了。
附上你的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(); }
内容的提问来源于stack exchange,提问作者Mike Ike
相关产品推荐
相关产品推荐

