【发布时间】:2019-05-18 23:39:35
【问题描述】:
我在 docker swarm 容器中运行 IdentityServer4 (identity-service)。这是我的堆栈文件中的服务设置:
identity-service:
image: identity:${TAG:-latest}
environment:
- DATABASE_CONNECTION_STRING=mongodb://mongo:27017
- ASPNETCORE_URLS=http://0.0.0.0:8080
- LOGGING_LEVEL=1
networks:
- proxy
- database
deploy:
replicas: 1
update_config:
parallelism: 1
delay: 10s
failure_action: rollback
order: start-first
labels:
- com.df.notify=true
- com.df.servicePath=${SERVICE_PATH:-/identity}
- com.df.port=8080
healthcheck:
test: ["CMD", "curl", "-f", "localhost:8080/health"]
interval: 5s
timeout: 10s
retries: 10
start_period: 10s
我也在使用IdentityModel2.Client 来请求令牌。这也通过另一个端点identity-service 在identity-service 中完成:/user/login。这就是我使用DiscoveryClient的方式:
var discoveryDocument = await new DiscoveryClient(hostUrl).GetAsync();
if (discoveryDocument.IsError) {
throw new Exception(
String.Format("Failed to find discovery document at url: {0}, received following token-endpoint: {1}",
hostUrl, discoveryDocument.TokenEndpoint));
}
return new TokenClient(discoveryDocument.TokenEndpoint, "Web", authorizationSecret);
如果我不在容器中运行它,这可以正常工作,但在 swarm 中运行时会抛出 Exception,因为由于某种原因,discoveryDocument.TokenEndpoint 是 null。我还尝试将 shell 放入容器中,以查看是否可以使用 curl 访问 http://0.0.0.0:8080/.well-known/openid-configuration,我确实这样做了。
(hostUrl 在容器中运行时为http://0.0.0.0:8080)
【问题讨论】:
标签: .net docker asp.net-core-2.0 identityserver4