Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to obtain configuration from IdentityServer4

Welcome, It is my first try of using Docker containers to host to services. I have two services: Integrity-Identity and Integrity-API.

Integrity-Identity is using the latest version of IdentityServer4. Here is Integrity-Identity Startup.cs configuration:

public IServiceProvider ConfigureServices(IServiceCollection services) {
        services.AddDbContext<IntegrityIdentityContext>(options =>
            options.UseSqlServer(Configuration["connectionString"]));

        services.AddIdentity<ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores<IntegrityIdentityContext>()
            .AddDefaultTokenProviders();

        services.AddMvc();

        services.AddIdentityServer(options => {
                options.IssuerUri = null;
            })
            .AddSigningCredential(Certificate.Certificate.Get())
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddInMemoryApiResources(Config.GetApiResources())
            .AddInMemoryClients(Config.GetClients())
            .AddAspNetIdentity<ApplicationUser>()
            .AddCorsPolicyService<InMemoryCorsPolicyService>();

        RegisterEventBus(services);
        services.AddTransient<Seeder>();

        var container = new ContainerBuilder();
        container.Populate(services);

        return new AutofacServiceProvider(container.Build());
    }

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

        app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod().AllowCredentials());
        app.UseIdentityServer();
        ConfigureEventBus(app);
        app.UseMvcWithDefaultRoute();
    }

Here is Integrity-API Startup class:

public IServiceProvider ConfigureServices(IServiceCollection services) {
        services.AddDbContext<IntegrityApiContext>(options =>
            options.UseSqlServer(Configuration["secrets:connectionString"]));

        services.AddMvcCore()
            .AddAuthorization()
            .AddJsonFormatters();

        services.AddAuthentication("Bearer")
            .AddIdentityServerAuthentication(options =>
            {
                options.Authority = Configuration["IdentityUrl"];
                options.ApiName = "integrity_api";
                options.RequireHttpsMetadata = false;
            });

        services.AddCors(options => { 
            options.AddPolicy("CorsPolicy",
                builder => builder.AllowAnyOrigin()
                    .AllowAnyMethod()
                    .AllowAnyHeader()
                    .AllowCredentials());
        });

        var container = new ContainerBuilder();
        container.Populate(services);

        return new AutofacServiceProvider(container.Build());
    }

docker-compose.override.yml (I am attaching it but I do not know is this importent for this problem)

integrity.identity:
  environment:
    - ASPNETCORE_ENVIRONMENT=Development
    - ASPNETCORE_URLS=https://0.0.0.0:443
    - ASPNETCORE_HTTPS_PORT=443
    - EventBusConnection=rabbitmq
  ports:
    - "5105:443"
  volumes:
    - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro

integrity.api:
  environment:
    - ASPNETCORE_ENVIRONMENT=Development
    - ASPNETCORE_URLS=https://+:443
    - ASPNETCORE_HTTPS_PORT=443
    - EventBusConnection=rabbitmq
    - IdentityUrl=https://integrity.identity
    - ApiUrl=https://integrity.api
  ports:
    - "5115:443"
  volumes:
    - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro

When I am trying to get resource from controller with [Authorize] property and with generated token, Identity-API returns this:

System.InvalidOperationException: IDX20803: Unable to obtain configuration from: 'https://integrity.identity/.well-known/openid-configuration'.
   at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)
   at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
   at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
   at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.AuthenticateAsync()
   at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme)
   at IdentityServer4.AccessTokenValidation.IdentityServerAuthenticationHandler.HandleAuthenticateAsync() in C:\local\identity\server4\AccessTokenValidation\src\IdentityServerAuthenticationHandler.cs:line 61
   at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.AuthenticateAsync()
   at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Edit 1

I forgot to add the /.well-known/openid-configuration works in browser and certificate/https is correct and working without any warnings.

like image 304
ksymek Avatar asked Nov 26 '18 14:11

ksymek


People also ask

Is IdentityServer4 obsolete?

The current version (IdentityServer4 v4. x) will be the last version we work on as free open source. We will keep supporting IdentityServer4 until the end of life of . NET Core 3.1 in November 2022.

What is IdentityServer4?

IdentityServer is an authentication server that implements OpenID Connect (OIDC) and OAuth 2.0 standards for ASP.NET Core. It's designed to provide a common way to authenticate requests to all of your applications, whether they're web, native, mobile, or API endpoints.

Is IdentityServer4 open source?

About IdentityServer4IdentityServer is a free, open source OpenID Connect and OAuth 2.0 framework for ASP.NET Core.


1 Answers

I found solution for this issue. The problem was caused for self signed local certificate. For local development I only need to change from HTTPS to HTTP. And that was it.

like image 92
ksymek Avatar answered Sep 24 '22 06:09

ksymek