【问题标题】:Azure Active Directory Reply URL redirecting to rootAzure Active Directory 回复 URL 重定向到根目录
【发布时间】:2017-08-22 10:05:10
【问题描述】:

我正在尝试使用 Azure AD 实现身份验证。在应用程序设置中,我将回复 URL 设置为 https://example.com/myapp/login.aspx。 当我登录时,它会将我重定向到https://example.com,而不是指定的 URL https://example.com/myapp/login.aspx

如何确保它重定向到正确的 URL?以下是启动的代码。

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

    app.UseCookieAuthentication(new CookieAuthenticationOptions());

    app.UseOpenIdConnectAuthentication(
        new OpenIdConnectAuthenticationOptions
        {
            ClientId = ConfigurationManager.AppSettings["owin:ClientId"].ToString(),
            Authority = "https://login.microsoftonline.com/yz5036e3-2951-4c11-af4d-da019fa6a57d",
            RedirectUri = ConfigurationManager.AppSettings["RedirectUri"].ToString()
        });
}

【问题讨论】:

    标签: asp.net azure openid azure-active-directory


    【解决方案1】:

    如何触发登录流程?如果您遵循示例并通过调用 Challenge 来启动登录,如 https://github.com/Azure-Samples/active-directory-dotnet-webapp-openidconnect/blob/master/WebApp-OpenIDConnect-DotNet/Controllers/AccountController.cs 所示,您可能需要确保 AuthenticationProperties 中的 RedirectUri 指向您最终(如 AFTER auth)想要登陆的 URL . 我知道,这非常令人困惑 - OIDC 选项中的 RedirectUri 属性指向您要在 auth 协议中使用的重定向,您希望在其上接收身份验证令牌的那个 - 而 AuthenticationProperties 中的一个是您想要的本地 URL在您与身份提供者的交换成功结束后被重定向到。由于历史原因,这些属性具有相同的名称。

    【讨论】:

      【解决方案2】:

      在我的情况下,网站位于虚拟目录下(在应用程序中转换)。对于登录 URL,例如http://example.com/myapp/login.aspx,它将用户重定向到http://example.com。如果我将 RedirectUri 设置为 myapp/AfterLogin.aspx,它可以工作。

      HttpContext.Current.GetOwinContext().Authentication.Challenge(
                  new AuthenticationProperties { RedirectUri = "myapp/AfterLogin.aspx", },
                  OpenIdConnectAuthenticationDefaults.AuthenticationType);
      

      【讨论】:

      • 或使用RedirectUri = Url.Content("~/AfterLogin.aspx") 避免对虚拟目录进行硬编码
      猜你喜欢
      • 2019-12-21
      • 2018-10-14
      • 2019-03-03
      • 1970-01-01
      • 1970-01-01
      • 2015-05-06
      • 1970-01-01
      • 1970-01-01
      • 2021-11-26
      相关资源
      最近更新 更多