我有一个 ASP.NET Core 2.0 Web 应用程序部署到 Kubernetes 集群。该应用程序使用 Azure AD 对某些受保护页面进行身份验证。Kubernetes 集群设置有 Nginx 入口控制器,让我们加密以支持 https。
我可以毫无问题地访问https://x.eastus.cloudapp.azure.com并且通过单击网站上的链接,我也会被定向到https://x.eastus.cloudapp.azure.com/link没有问题。
但是,当我单击需要登录用户的链接时,我得到:
Sign in
Sorry, but we’re having trouble signing you in.
AADSTS50011: The reply address 'http://x.eastus.cloudapp.azure.com/signin-oidc' does not match the reply addresses configured for the application: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx'. More details: not specified
请注意,上面的 URL 缺少 https,这就是问题所在。
我已将“ https://x.eastus.cloudapp.azure.com/signin-oidc ”注册为 Azure AD 中应用程序的回复 URL。
但是,我不明白为什么登录时使用的回复网址缺少 https。
如果我将完全相同的应用程序部署到 Azure Web 应用程序,我不会遇到这个问题。
可能是什么问题?
这是我的入口 YAML 文件:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: x-ingress
annotations:
kubernetes.io/ingress.class: nginx
# Add to generate certificates for this ingress
kubernetes.io/tls-acme: 'true'
spec:
rules:
- host: x.eastus.cloudapp.azure.com
http:
paths:
- path: /
backend:
serviceName: x-service
servicePort: 80
tls:
# With this configuration kube-lego will generate a secret called `x-tls-secret`
# for the URL `x.eastus.cloudapp.azure.com`
- hosts:
- "x.eastus.cloudapp.azure.com"
secretName: x-tls-secret
我在 Startup.cs 中有以下代码:
public void ConfigureServices(IServiceCollection services)
{
services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders =
ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
});
services.Configure<MvcOptions>(options =>
{
options.Filters.Add(new RequireHttpsAttribute());
});
services.AddAuthentication(sharedOptions =>
{
sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddAzureAd(options => Configuration.Bind("AzureAd", options))
.AddCookie();
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseForwardedHeaders();
app.UseStaticFiles();
app.UseAuthentication();
}