sách gpt4 ai đã đi

azure - 在反向代理后面使用 Azure AD 身份验证的 ASP.NET Core 应用程序设置了错误的 redirect_uri

In lại 作者:行者123 更新时间:2023-12-03 03:56:46 25 4
mua khóa gpt4 Nike

我已经为此苦恼了一段时间了。我有一个在 Azure 应用服务上运行的 ASP.NET Core 3.1 Web 应用程序。 Web 应用程序具有 Azure AD 身份验证设置,并带有转发 header 。这是ConfigureService:

services.Configure(options =>
{
options.ForwardedHeaders =
ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
});

services
.AddAuthentication(AzureADDefaults.AuthenticationScheme)
.AddAzureAD(options =>
{
Configuration.Bind("AzureAd", options);
});

Đây là配置:

if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseForwardedHeaders();
}
khác
{
app.UseExceptionHandler("/Error");
app.UseForwardedHeaders();
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseSpaStaticFiles();

app.UseRouting();
app.UseCors(Configuration["AllowedHosts"]);
app.UseAuthentication();
app.UseAuthorization();

我使用 Azure 应用程序网关作为反向代理。 身份验证流程中出现问题。经过身份验证后,URL 中提供的 redirect_uri 是 *.azurewebsites.net 地址,而不是我在应用程序网关 *.mydomain.com 中配置的地址。进一步调查显示,请求中向应用服务提供了以下 header :

X-FORWARDED-PROTO: https
X-FORWARDED-PORT: 443
X-Forwarded-For: ***IP ADDR OF APP GATEWAY***
X-Original-URL: ***
X-ORIGINAL-HOST: *.mydomain.com
X-ARR-SSL: 2048|256|C=US, S=Washington, L=Redmond, O=Microsoft Corporation, OU=Microsoft IT, CN=Microsoft IT TLS CA 5|CN=*.azurewebsites.net
X-AppService-Proto: https
X-Forwarded-TlsVersion: 1.2

我还需要告诉我的后端应用程序使用转发的 header (在我的情况下,X-ORIGINAL-HOST 似乎是唯一包含实际请求主机的 header )?这看起来是一个非常简单的用例。预先感谢您的帮助。

1 Câu trả lời

在主机名设置下的 HTTP 设置中,提及 *.domain.com。如果您进行更改,请确保您已使用自定义域配置后端。

问候,姆斯里尼

关于azure - 在反向代理后面使用 Azure AD 身份验证的 ASP.NET Core 应用程序设置了错误的 redirect_uri,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64298867/

25 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com