2

我已經讀了很多指南/文章,但還沒有找到一個還沒有,它正是我想要的......那就是通過形式來實現在ASP.NET Web API的Active Directory認證。如何通過Forms在ASP.NET Web API中實現Active Directory身份驗證?

事情是這樣的指南:

Cool MVC 5 guide to implement authentication with Active Directory

這是非常好的,但它是MVC,即,它採用了控制器不是ApiController

可有人請給我提示/提示/關於如何開始的文章?特別是關於連接到活動目錄的部分。我一直堅持這一點。

UPDATE:

public bool IsAuthenticatedUser(string srvr, string usr, string password) 
     { 
      bool authenticated = false; 

      try { 
       DirectoryEntry entry = new DirectoryEntry(srvr, usr, password); 
       object nativeObject = entry.NativeObject; 
       Object obj = entry.NativeObject; 
       authenticated = true; 
      } 
      catch { 
       throw new HttpResponseException(HttpStatusCode.Unauthorized); 
      } 
      return authenticated; 
     } 

     // POST: api/Login 
     public void Post([FromBody]string username, [FromBody]string password) 
     { 
      if (IsAuthenticatedUser("LDAP string", username, password)) 
      { 
       Redirect("Index"); 
      } 
      else 
      { 
       throw new HttpResponseException(HttpStatusCode.Unauthorized); 
      } 
     } 

我想嘗試像這樣的認證,你的想法?

回答

1

嗯,我不認爲這是正確的,使FOREST身份驗證WebApi的WebAPI的感正在與數據在的RESTful方式。

所以我的建議是(如果你想使用的廣告格式驗證):

1)創建測試環境中測試廣告認證 - 爲了這個目的,你可以使用Oracle VirtualBox的 。就可以了,要安裝的Windows Server 2016(評估爲180天),在那裏你建立AD,創建域和一些測試用戶添加到它,安裝AD SSL證書(手工製作是OK);

2)主機上安裝從1證書)爲SSL主機和虛擬個人電腦(因爲你要發送純憑證)之間的連接;

3)在你的Web應用程序,使傳統MVC登錄頁面,使用SSL cookie來存儲憑據信息:你創建你的身份驗證控制器方法這個cookie。驗證過程是如的web.config寫入正確連接字符串System.Web.Security.ActiveDirectoryMembershipProvider,檢查用戶有效性普通Membership.ValidateUser方法一樣簡單;

4)一旦用戶被成功驗證,使用保存的Cookie來驗證請求

的WebAPI之間的用戶
相關問題