【发布时间】:2021-05-03 08:45:21
【问题描述】:
我想在 Docker 中部署 IdentityServer4 和 MVC 客户端。作为反向代理,我使用 NGINX。但是我的容器无法访问外部网络。 (下图红线)
我的 MVC 客户端应用程序通过内部网络请求发现文档并接收内部 URI。但是它们被浏览器中的客户端代码使用。 FQDN 可以是带有端口或常规域名的 IP 地址。需要做什么来解决我的问题? 我找到了similar question。建议使用相同的 DNS 名称并将其在 docker-compose 网络中解析为 IdentityServer4 容器。但是在IP地址的情况下怎么办? this answer 也有同样的问题。 我什至考虑过迁移到 oidc-client.js。但这会花费太多时间。
MVC 客户端:
services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies")
.AddOpenIdConnect("oidc", options =>
{
options.Authority = "http://fqdn/idsrv";
options.RequireHttpsMetadata = false;
options.ClientId = "mvc";
options.SaveTokens = true;
});
IdentityServer4:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_1);
var builder = services.AddIdentityServer(o => {
})
.AddInMemoryIdentityResources(Config.GetIdentityResources())
.AddInMemoryApiResources(Config.GetApis())
.AddInMemoryClients(Config.GetClients())
.AddTestUsers(Config.GetUsers());
builder.AddDeveloperSigningCredential();
}
public void Configure(IApplicationBuilder app)
{
app.UsePathBase("/idsrv");
app.UseDeveloperExceptionPage();
app.UseStaticFiles();
app.UseIdentityServer();
app.UseMvcWithDefaultRoute();
}
docker-compose:
version: "3.9"
services:
mvcclient:
build:
context: .
dockerfile: \MvcClient\Dockerfile
identityserver:
build:
context: .
dockerfile: \IdentityServer\Dockerfile
proxy:
image: nginx
ports:
- "80:80"
NGINX:
location ~* ^/idsrv {
proxy_pass http://identityserver;
}
location ~* ^/mvcclient {
proxy_pass http://mvcclient;
}
【问题讨论】:
标签: docker asp.net-core authentication identityserver4 openid-connect