![](/img/trans.png)
[英]IdentityServer4: Unable to obtain configuration from: 'https://myServer/.well-known/openid-configuration
[英]Unable to obtain configuration from IdentityServer4
歡迎,這是我第一次嘗試使用Docker容器來托管服務。 我有兩個服務: Integrity-Identity
和Integrity-API
。
Integrity-Identity
使用最新版本的IdentityServer4。 這是Integrity-Identity
Startup.cs
配置:
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();
}
這是Integrity-API
Startup
類:
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
(我正在附加它,但我不知道這個問題docker-compose.override.yml
)
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
當我嘗試使用[Authorize]
屬性和生成的令牌從控制器獲取資源時, Identity-API
返回以下內容:
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)
我忘了添加/.well-known/openid-configuration
在瀏覽器中工作,並且certificate / https是正確的,並且沒有任何警告。
我找到了解決這個問題的方法。 問題是由自簽名本地證書引起的。 對於本地開發,我只需要從HTTPS更改為HTTP。 就是這樣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.