【发布时间】:2018-08-26 17:50:59
【问题描述】:
我有一个 .NET Core 2.0 网站,在 Linux 上运行,监听端口 5000,在 NGinX 反向代理后面,监听端口 80 和 442。NGinX 配置为将 HTTP 流量重定向到 HTTPS,并处理所有通信通过 HTTPS。 NGinx 反向代理和 Asp.Net Core 应用程序位于它们自己的 docker 容器中,位于共享网络上。
此设置当前正在按说明工作。
但是,我现在想针对我们的 Azure Active Directory 对我的用户进行身份验证。我遇到了一个问题,不知道从哪里开始。
首先,让我向您展示我是如何配置大部分内容的,然后我将解释我的错误。
NGinx (nginx.conf)
worker_processes 2;
events { worker_connections 1024; }
http {
sendfile on;
upstream docker-dotnet {
server mycomp_prod:5000;
}
server {
listen 80;
server_name sales.mycompany.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name sales.mycompany.com;
ssl_certificate /etc/nginx/ssl/combined.crt;
ssl_certificate_key /etc/nginx/ssl/salesmycompany.key;
location / {
proxy_pass http://docker-dotnet;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
}
Dotnet:Startup.cs ConfigureServices()
services.AddAuthentication(sharedOptions =>
{
sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddAzureAd(options => Configuration.Bind("AzureAd", options))
.AddCookie();
Dotnet:Startup.cs Configure()
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
app.UseAuthentication();
Dotnet:appsettings.json
{
"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"Domain": "mycompany.com",
"TenantId": "my-tenant-id",
"ClientId": "my-client-id",
"CallbackPath": "/signin-oidc"
},
在我的 Azure Active Directory 租户中
我已经配置了 2 个“回复 URL”
现在是错误/我的问题
当我访问该站点时,我会登录。然后登录并选择是否“保持登录状态”,我被带到一个错误的页面。
您可以在错误中看到,尝试重定向到的回复地址是 HTTP,而不是 HTTPS。我认为这是来自 appsettings.json 中的一行:
"CallbackPath": "/signin-oidc"
由于我的 .NET Core 站点(通过端口 5000 上的 Kestrel)不在 HTTPS 上,因此它正在尝试加载 http://example.com/signin-oidc,而不是 HTTPS。请记住,我的 .NET Core 站点位于 NGinX 反向代理后面,该代理配置为处理 443 上的流量。
谢谢,
【问题讨论】:
-
appsettings.json中的BaseUrl是什么?应阅读https://...,然后在与 AAD 回复 URL 匹配时附加CallbackPath。我在您的列表中没有看到它,所以请尝试添加它。 -
在 appsettings.json 中,“BaseUrl”是“AzureAd”上的属性,还是在其他对象下?我查看了 docs.microsoft.com,似乎找不到有关此属性的文档。你能带我看一下这个属性的文档吗?
标签: azure asp.net-core azure-active-directory