2017-08-22 40 views
0

我試圖使用Azure AD實現身份驗證。在應用程序設置中,我將回復URL設置爲https://example.com/myapp/login.aspx。 當我登錄時,它將我重定向到https://example.com而未指定URL https://example.com/myapp/login.aspx重定向到根的Azure Active Directory響應URL

如何確保它重定向到正確的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() 
     }); 
} 

回答

2

你如何觸發登錄流程?如果您按照示例https://github.com/Azure-Samples/active-directory-dotnet-webapp-openidconnect/blob/master/WebApp-OpenIDConnect-DotNet/Controllers/AccountController.cs中的示例並通過調用Challenge啓動登錄,則可能需要確保AuthenticationProperties中的RedirectUri指向您最終(如在,AFTER身份驗證中)想要着陸的URL。 我知道,這是令人難以置信的混淆--OIDC選項中的RedirectUri屬性指向您想要在auth協議中使用的重定向,您想在其上接收auth令牌 - 而AuthenticationProperties中的那個是本地URL希望在與身份提供商交換後成功完成重定向。由於歷史原因,這些過程具有相同的名稱。

0

在我的情況下,網站是在虛擬目錄(在應用程序中轉換)。對於登錄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);