gpt4 book ai didi

azure - 使用 azure 进行身份验证时 Post_Logout_Redirect_Uri 不会重定向

转载 作者:行者123 更新时间:2023-12-03 13:40:20 28 4
gpt4 key购买 nike

使用 OWIN 和 OpenId 对使用 Azure Active Directory 的基本 Web 应用程序的用户进行身份验证,如 Microsoft 示例项目中的 Readme.md 中所述:https://github.com/Azure-Samples/active-directory-dotnet-webapp-openidconnect

以下项目位于我的 web.config 中:

<add key="ida:PostLogoutRedirectUri" value="https://localhost:44320/" />

Startup.Auth如下:

    private static string clientId = ConfigurationManager.AppSettings["ida:ClientId"];
private static string aadInstance = ConfigurationManager.AppSettings["ida:AADInstance"];
private static string tenant = ConfigurationManager.AppSettings["ida:Tenant"];
private static string postLogoutRedirectUri = ConfigurationManager.AppSettings["ida:PostLogoutRedirectUri"];

string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);

public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

app.UseCookieAuthentication(new CookieAuthenticationOptions());

app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
Authority = authority,
PostLogoutRedirectUri = postLogoutRedirectUri,
RedirectUri = "https://localhost:44320/Home/About",
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthenticationFailed = context =>
{
context.HandleResponse();
context.Response.Redirect("/Error?message=" + context.Exception.Message);
return Task.FromResult(0);
}
}
});
}
}

但是,即使重定向 URI 已进入其 URL enter image description here,microsoft.com 网站也不会重定向。

最佳答案

我花了很多时间来正确地弄清楚如何让它发挥作用。即使三年前我们只是没有打扰。互联网上似乎有很多人都遇到了这个问题,我想确保每个人都能找到这个问题的答案。

以下解决方案适用于标准 Azure AD 发生的问题。如果您使用组织帐户登录,它也适用于 Azure AD B2C。 (请注意,此解决方案不涵盖新的 b2clogin URI 和用户流技术,因为在我提出问题时它还不存在)

  1. 在提出此问题时,Azure 中似乎存在某种错误。解决方法如下:用作注销后重定向的 URI 必须在回复 URL 和前端 channel 注销 URL 中指定。通常,前 channel 注销是 IDP 发送到您的应用程序的静默请求,以允许您运行逻辑来清除 cookie,但不会导致重定向。在实现此操作之前,您应该检查 Microsoft 是否已修复该问题。 enter image description here请小心不要在 URI 末尾意外添加尾部斜杠。尽量让它们在此处和您的客户端应用程序中完全相同。

  2. https://login.microsoftonline.com/<org-name>.onmicrosoft.com/V2.0 形式的权威行不通。对于标准 Azure AD,我必须将权限更改为 https://login.microsoftonline.com/<tenant-id>/V2.0 形式对于特定租户或 https://login.microsoftonline.com/common/V2.0我认为这也用于某些场景。对于 B2C AD 租户,它仅适用于 common上面的端点。

旁注 1:使用 common您必须设置端点 ValidateIssuer在 token 验证参数中设置为 false,否则您将收到异常。正确进行验证超出了这个问题的范围。

旁注 2:在 Google 上搜索此问题时,您可能会遇到一些针对 Identity Server 身份验证问题的解决方案。解决方案和规范建议您将 id_token_hint 添加到注销请求中。对于我来说,要让重定向适用于 Azure AD,这既不够也没有必要。

关于azure - 使用 azure 进行身份验证时 Post_Logout_Redirect_Uri 不会重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47419128/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com