3
votes

I've created a basic core application using the identityserver4 middleware. I've setup resources and clients in the database. I've also added self signed certificates for signing messages. IdentityServer4 appears to be functioning correctly but I see a debug message that bothers me...

AuthenticationScheme: "idsrv" was not authenticated.

I have only created one flow (client_credentials) in my identity server. Does anyone have any idea why I would see this message?

In a effort to get a proper response, I added the Startup.cs below.

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

1 Answers

-1
votes

Add the following lines to your "ConfigureServices" in "Startup.cs"

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

Then add the following to your "Configure" in "Startup.cs"

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

To your "Configure" method in Startup.cs

Try authenticate.

If not works modify your [Authorize] to [Authorize(AuthenticationSchemes = "Bearer"]