1

我正在使用azure AD登錄選項(OpenId身份驗證)的mvc應用程序。我需要爲管理員提供模擬選項。所以我決定爲這個模擬登錄使用表單身份驗證。現在我的問題是,在webconfig中啓用表單身份驗證會影響azure AD登錄。一旦添加了表單身份驗證,它將連續顯示與belo url的重定向, http://localhost:9666/members/logon?ReturnUrl=%2fmembers%2flogonusingazure%3freturnUrl%3d%2f&returnUrl=/在相同的mvc應用程序中使用表單身份驗證和Azure AD登錄

用於Web配置中的表單驗證代碼。

<authentication mode="Forms"> 
     <forms loginUrl="~/members/logon" cookieless="UseCookies" name="MvcForumAuth" slidingExpiration="true" timeout="432000" /> 
    </authentication> 

感謝, Nagaraj M.

回答

1

Forms身份驗證是舊版本的ASP.NET,在Visual Studio的最新版本的ASP.NET MVC的默認模板的認證框架具有的實現ASP.NET身份框架。

你可以嘗試使用OWIN CookieAuthentication和ASP.NET的身份來處理與OpenIdConnect的本地認證AzureAD認證。

要使用asp.net身份,如果使用個人帳戶進行身份驗證以生成新的MVC項目,除了擁有用於直接身份驗證和ExternalLogin的登錄操作的帳戶控制器之外,您還可以看到Startup類的自動生成的代碼(第三方)。

然後你可以使用ASP.Net ID連接OWIN中間件登錄的用戶從Azure中的Active Directory租戶:

  1. 安裝Microsoft.Owin.Security.OpenIdConnect庫的NuGet。
  2. Startup

    ,設置OpenIdConnect管道:

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

    現在,您可以登錄到本地標識帳戶和蔚藍的廣告帳戶爲外部用戶您的應用程序:enter image description here

另外,您需要設置<authentication mode="none" />在web.config讓OWIN接管認證/授權過程從IIS應用程序。

1

按照上面難遇的建議, 有時候應用程序嘗試做一個Azure的廣告/ OpenID登錄之前得到身份登錄頁面。 我不明白爲什麼,但配置到表單認證似乎工作正常

<authentication mode="Forms"> 
     <forms loginUrl="~/Account/Login/" timeout="2880"/> 
</authentication> 
相關問題