Tuesday, 9 October 2018

Office 365 - Current login User Details

I generally needs to go to google each time to get current login User details for Office 365. Here is post for general idea how you can get the details in Office 365:

Approach 1 - Use Graph API

If you want to use Graph api, follow below steps,

  • go to below URL
    https://developer.microsoft.com/en-us/graph/graph-explorer
  • Sign in with your O365 details. 

  • Once you are logged in, click on "my profile" and it will get all your details.

How to use this in code,  I will write another blog for same.


Approach 2 - Use browser Console


Some of the properties are available using "_spPageContextInfo". Like user display name, user email address and user login name.

  • user display name - _spPageContextInfo.userDisplayName
  • user email - _spPageContextInfo.userEmail
  • user login name - _spPageContextInfo.userLoginName
  • user Id - _spPageContextInfo.userId
Approach 3 - Use Rest API (Ajax request)

To get other details you need to use below ajax request:

function getCurrUsrImg(){

var siteurl = _spPageContextInfo.webAbsoluteUrl;
        Var usrId = _spPageContextInfo.userId;
var userURL = siteurl + "/_api/web/SiteUserInfoList/Items('"+usrId+"')";
$.ajax({
url: userURL,
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
async: true,
success: function (data) {
getCurrUserIMGSuccess(data.d);
},
error: function (data) {
console.log("Error: "+ data);
}
});
}

function getCurrUserIMGSuccess(res){
//console.log("llll");

var uHTMLIMG = "";
if(res.Picture != null){
uHTMLIMG = "<img src='"+res.Picture["Url"]+"'>";
}

$('#divCuserimg').html("");
$('#divCuserimg').html(uHTMLIMG);
}

You can get below list of fields with this call:

  • Id
  • ContentTypeId
  • Title (full name - love thakker)
  • Name (domain name - i:0#.f|membership|love.thakker)
  • EMail
  • MobilePhone
  • SipAddress
  • Deleted (true / false)
  • Picture ( look up - expand with description and URL)       
  • Department       
  • JobTitle        
  • FirstName        
  • LastName
  • WorkPhone      
  • UserName        
  • GUID   
  • Modified      
  • Created       
  • AuthorId
  • EditorId

Approach 4 - Use People Manager api (Ajax request)
If you want even more details than this then you can use below service call

$.ajax({  
  
            url: _spPageContextInfo.siteAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties",  
            headers: { Accept: "application/json;odata=verbose" },  
            success: function (data) {  
                try {  
                    //Get properties from user profile Json response  
                    userDisplayName = data.d.DisplayName;  
                    AccountName = data.d.AccountName;  
                    var properties = data.d.UserProfileProperties.results;  
                    for (var i = 0; i < properties.length; i++) {  

                        var property = properties[i];  
                        if (property.Key == "Office") {  
location = property.Value;
                        }  

                    }
                } catch (err2) {  
                  console.log('error');
                }  
            },  
            error: function (jQxhr, errorCode, errorThrown) {  
                alert(errorThrown);  
            }  
        });  
        

}

Below is list of columns that you will get when you use this:
  • AccountName
  • DisplayName
  • Email
  • ExtendedManagers
  • ExtendedReports
  • Peers
  • PersonalSiteHostUrl (-my.sharepoint.com)
  • PersonalUrl (my.sharepoint.com/personal/love_thakker)
  • PictureUrl
  • Title
  • UserProfileProperties
    • UserProfile_GUID
    • SID
    • ADGuid
    • AccountName
    • FirstName
    • SPS-PhoneticFirstName
    • LastName
    • SPS-PhoneticLastName
    • PreferredName
    • SPS-PhoneticDisplayName
    • WorkPhone
    • Department
    • Title
    • SPS-Department
    • Manager
    • AboutMe
    • PersonalSpace
    • PictureURL
    • UserName
    • QuickLinks
    • WebSite
    • PublicSiteRedirect
    • SPS-JobTitle
    • SPS-DataSource
    • SPS-MemberOf
    • SPS-Dotted-line
    • SPS-Peers
    • SPS-Responsibility
    • SPS-SipAddress
    • SPS-MySiteUpgrade
    • SPS-DontSuggestList
    • SPS-ProxyAddresses
    • SPS-HireDate
    • SPS-DisplayOrder
    • SPS-ClaimID
    • SPS-ClaimProviderID
    • SPS-LastColleagueAdded
    • SPS-OWAUrl
    • SPS-ResourceSID
    • SPS-ResourceAccountName
    • SPS-MasterAccountName
    • SPS-UserPrincipalName
    • SPS-O15FirstRunExperience
    • SPS-PersonalSiteInstantiationState
    • SPS-DistinguishedName
    • SPS-SourceObjectDN
    • SPS-LastKeywordAdded
    • SPS-ClaimProviderType
    • SPS-SavedAccountName
    • SPS-SavedSID
    • SPS-ObjectExists


No comments:

Post a comment