【发布时间】:2021-06-05 08:04:29
【问题描述】:
我正在尝试将 IdentityServer 4 配置为在 Docker 中工作,身份服务器容器本身正在运行,但我无法从客户端连接到它。
我的申请包括:
- API
- 客户
- 身份服务器4
我的 docker compose 看起来像
services:
client:
image: ${DOCKER_REGISTRY-}client
ports:
- '6001:80'
build:
context: .
dockerfile: UI/client.UI/Dockerfile
depends_on:
- db
identityserver:
image: ${DOCKER_REGISTRY-}identityserver
ports:
- '5001:443'
build:
context: .
dockerfile: Security/IdentityServer/Dockerfile
depends_on:
- db
apiservice:
image: ${DOCKER_REGISTRY-}apiservice
build:
context: .
dockerfile: API/Services/api.Service/Dockerfile
depends_on:
- db
db:
image: "mcr.microsoft.com/mssql/server:2019-latest"
environment:
SA_PASSWORD: "PaSSw0rd"
ACCEPT_EULA: "Y"
MSSQL_PID: Express
ports:
- "1433:1433"
volumes:
- mssql-volume:/var/opt/mssql
networks:
default:
driver: bridge
volumes:
mssql-volume:
我的身份服务器StartUp 类:
public void ConfigureServices(IServiceCollection services)
{
....
var builder = services.AddIdentityServer(options =>
{
options.Events.RaiseErrorEvents = true;
options.Events.RaiseInformationEvents = true;
options.Events.RaiseFailureEvents = true;
options.Events.RaiseSuccessEvents = true;
options.UserInteraction.LoginUrl = "/Account/Login";
options.UserInteraction.LogoutUrl = "/Account/Logout";
options.Authentication = new AuthenticationOptions()
{
CookieLifetime = TimeSpan.FromHours(10), // ID server cookie timeout set to 10 hours
CookieSlidingExpiration = true
};
options.IssuerUri = "https://172.20.16.1:5001";
})
.AddConfigurationStore(options => // this adds the config data from DB (clients, resources)
{
...
})
.AddOperationalStore(options =>// this adds the operational data from DB (codes, tokens, consents)
{
...
})
.AddDeveloperSigningCredential()
.AddAspNetIdentity<ApplicationUser>();
}
我的客户StartUp类:
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(options =>
{
options.DefaultScheme = "cookie";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("cookie")
.AddOpenIdConnect("oidc", options =>
{
options.Authority = "https://172.20.16.1:5001";
options.RequireHttpsMetadata = false;
options.ClientId = "ClientMVC";
options.ClientSecret = "SuperSecretPassword";
options.SaveTokens = true;
options.ResponseType = "code";
options.UsePkce = true;
options.ResponseMode = "query";
options.GetClaimsFromUserInfoEndpoint = true;
options.Scope.Clear();
options.Scope.Add("openid");
.. some scopes
});
}
我收到以下错误
AuthenticationException:根据验证程序,远程证书无效:
远程证书名称不匹配,远程证书链错误
System.Net.Security.SslStream.SendAuthResetSignal(ProtocolToken 消息,ExceptionDispatchInfo 异常)HttpRequestException:无法建立 SSL 连接,请参阅内部异常。
System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(bool async, Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancelToken)IOException:IDX20804:无法从“System.String”检索文档。
Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(字符串地址,CancellationToken 取消)
InvalidOperationException:IDX20803:无法从“System.String”获取配置。
Microsoft.IdentityModel.Protocols.ConfigurationManager.GetConfigurationAsync(CancellationToken cancel)
我尝试使用以下命令添加证书
dotnet dev-certs https -ep %USERPROFILE%\.aspnet\https\IdentityServer.pfx -p passw0rd!
dotnet dev-certs https --trust
但这会将证书添加到localhost,这在这种情况下无效。
有什么帮助吗?
【问题讨论】:
标签: docker docker-compose asp.net-core-mvc microservices identityserver4