1

This is about Implementation of single sign on in PHP.

I have a website say abc.com, I want to check, is user logged into his/her outlook mail? Means I want to get email address of the user from his local machine by using website to implement Single sign-in on web.

Or you can say I want to check user profile (email-id which one used on windows machine to get access windows applications)

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.

vinod
  • 2,850
  • 1
  • 18
  • 23

2 Answers2

1

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.

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. In .Net simple code for getting AD user with domain is :

     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.

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):

   $(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.

priti narang
  • 258
  • 4
  • 18
0

You can just use Microsoft Graph SDK for PHP to make Outlook API Calls. 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.

Tiago Martins Peres
  • 14,289
  • 18
  • 86
  • 145