IdentityServer4调试消息AuthenticationScheme:“idsrv”未经过身份验证

时间:2018-01-14 03:05:42

标签: c# asp.net-core identityserver4

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

  

AuthenticationScheme:“idsrv”未经过身份验证。

我只在我的身份服务器中创建了一个流(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();
}

1 个答案:

答案 0 :(得分:0)

将以下行添加到“ 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”中的“配置”中

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

转到Startup.cs中的“配置”方法

尝试进行身份验证。

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