簡體   English   中英

如何使用 PHP 從我的網站訪問 windows 服務或來自 windows 機器的數據?

[英]How can I access windows services or data from windows machine from my website using PHP?

這是關於 PHP 中單點登錄的實現。

我有一個網站說 abc.com,我想檢查一下,用戶是否登錄了他/她的 outlook 郵件? 表示我想通過使用網站在 web 上實現單點登錄,從用戶的本地計算機獲取用戶的 email 地址。

或者您可以說我想檢查用戶配置文件(在 windows 機器上使用的電子郵件 ID 以訪問 windows 應用程序)

如果用戶使用 window 系統並且他登錄到 outlook 這意味着任何特定的網站、鏈接或 api 將返回一些標志等,可能還有另一種解決方法。

活動目錄用於管理網絡內的用戶,現在微軟使用基於雲的解決方案,如 Azure 和 SAML 2.0 等。

但是,您的問題是關於活動目錄的使用,那么首先您必須了解活動目錄域設置,AD 用於獲取系統用戶信息以驗證為特定用戶創建的訪問級別。 In.Net 獲取具有域的 AD 用戶的簡單代碼是:

     public static void Main() {
     DisplayUser(WindowsIdentity.GetCurrent());
     Console.ReadKey();    
 }

 public static void DisplayUser(IIdentity id) {    
     WindowsIdentity winId = id as WindowsIdentity;
     if (id == null) {
         Console.WriteLine("Identity is not a windows identity");
         return;
     }

     string userInQuestion = winId.Name.Split('\\')[1];
     string myDomain = winId.Name.Split('\\')[0]; // this is the domain that the user is in
      // the account that this program runs in should be authenticated in there                    
     DirectoryEntry entry = new DirectoryEntry("LDAP://" + myDomain);
     DirectorySearcher adSearcher = new DirectorySearcher(entry);

     adSearcher.SearchScope = SearchScope.Subtree;
     adSearcher.Filter = "(&(objectClass=user)(samaccountname=" + userInQuestion + "))";
     SearchResult userObject = adSearcher.FindOne();
     if (userObject != null) {
         string[] props = new string[] { "title", "mail" };
         foreach (string prop in props) {
             Console.WriteLine("{0} : {1}", prop, userObject.Properties[prop][0]);
         }
     }
 }

實際上,獲取系統用戶名和獲取用於 Microsoft 登錄的 email 地址是不同的兩個過程。

要獲取系統或操作系統用戶,您可以使用下面的 javascript 代碼,稱為 activeXObject,為此您必須在 IE 中從安全選項卡中啟用 activeXObject(我剛剛為 Internet Explorer 測試過):

   $(document).ready(function () { 

     try {
      var activex = new ActiveXObject('WScript.Network');
      alert(activex.userName);
    } catch (ex) {
      alert("unable to get user info");
    }
}

所以最后回答你的問題,你不能在不使用 AD 或 SAML 等的情況下直接獲得 email id。

您可以使用Microsoft Graph SDK for PHP來制作Outlook ZDB97423871048DE63FZA7ACE1 調用 為了做到這一點,您可以按照本教程進行操作。

這將要求用戶每次登錄以授予訪問權限。 要修復它,已經有答案了

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM