Monday, August 3, 2015

Azure AD Graph API cannot access Microsoft Account


Problem 1:

User.Identity.Name is null for Microsoft users.

Solution

in Global.ascx, write following code,
 protected void Application_PostAuthenticateRequest(Object sender, EventArgs e)
        {
            ClaimsIdentity id = ((ClaimsIdentity)User.Identity);
            Claim claim = id.FindFirst(ClaimTypes.Email);
            if (claim != null)
            {
                string email = claim.Value;
                id.AddClaim(new Claim(ClaimTypes.Name, email));
            }
        }


Problem 2: 

https://graph.windows.net/tenantid/users/testemail@hotmail.com ?api-version=2013-04-05 is not returning user profile which the same api works for the local users of AD.

Solution

https://graph.windows.net/contoso.com/users?api-version=2013-11-08&$filter=startswith(userPrincipalName, 'testemail_hotmail')

No comments:

Post a Comment