[英]How can I access windows services or data from windows machine from my website using PHP?
This is about Implementation of single sign on in PHP.这是关于 PHP 中单点登录的实现。
I have a website say abc.com, I want to check, is user logged into his/her outlook mail?
我有一个网站说 abc.com,我想检查一下,用户是否登录了他/她的 outlook 邮件? Means I want to get email address of the user from his local machine by using website to implement Single sign-in on web.
表示我想通过使用网站在 web 上实现单点登录,从用户的本地计算机获取用户的 email 地址。
Or you can say I want to check user profile (email-id which one used on windows machine to get access windows applications)
或者您可以说我想检查用户配置文件(在 windows 机器上使用的电子邮件 ID 以访问 windows 应用程序)
May be there is another workaround for this like if user is using window system & he is logged into the outlook its mean any specific website, link or api will return some flag etc.如果用户使用 window 系统并且他登录到 outlook 这意味着任何特定的网站、链接或 api 将返回一些标志等,可能还有另一种解决方法。
Active directory is used for managing users within a network, now a days Microsoft using cloud based solutions like Azure with SAML 2.0 etc.
活动目录用于管理网络内的用户,现在微软使用基于云的解决方案,如 Azure 和 SAML 2.0 等。
However your question is about use of active directory then first of all you have to understand about active directory domain settings, AD is used for getting system user info to verify access level created for a specific user.
但是,您的问题是关于活动目录的使用,那么首先您必须了解活动目录域设置,AD 用于获取系统用户信息以验证为特定用户创建的访问级别。 In.Net simple code for getting AD user with domain is:
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]);
}
}
}
Actually both getting system user name & getting email address used for Microsoft login are different-2 processes.实际上,获取系统用户名和获取用于 Microsoft 登录的 email 地址是不同的两个过程。
To get system or OS user you can use below javascript code, known as a activeXObject, for this you have to enable activeXObject in IE from security tab (I just tested this for Internet explorer):要获取系统或操作系统用户,您可以使用下面的 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");
}
}
So finally answer of your question you can't get email id directly without using AD or SAML etc.
所以最后回答你的问题,你不能在不使用 AD 或 SAML 等的情况下直接获得 email id。
You can just use Microsoft Graph SDK for PHP to make Outlook API Calls .您可以使用Microsoft Graph SDK for PHP来制作Outlook ZDB97423871048DE63FZA7ACE1 调用。 In order to do it, you can follow this tutorial .
为了做到这一点,您可以按照本教程进行操作。
This will require the user to login every time to give access.这将要求用户每次登录以授予访问权限。 To fix it, there's already an answer for it .
要修复它,已经有答案了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.