Skip to content

Instantly share code, notes, and snippets.

@ktskumar
Created March 12, 2020 10:18
Show Gist options
  • Save ktskumar/f4c5acfa0a5ee0e8066672ed61c9db99 to your computer and use it in GitHub Desktop.
Save ktskumar/f4c5acfa0a5ee0e8066672ed61c9db99 to your computer and use it in GitHub Desktop.
How to get Current User AAD ID and Tenant ID from SharePoint
//getRequest method reference
//https://gist.github.com/ktskumar/a9e9df497673e9fd26ead8532b9ff425
//Get the Request location from the browser URL
var path = location.href.replace(location.search, "") + "?as=json";
if (!window._isSPSitePage) //Validate the current page not a modern Site Page
console.log("User ID: " + _spPageContextInfo.aadUserId + " - Tenant ID: " + _spPageContextInfo.aadTenantId);
else { // If the current page is modern page
getRequest(path).then(function(response) {
var currentContext = JSON.parse(response.response);
console.log("User ID: " + currentContext.spPageContextInfo.aadUserId + " - Tenant ID: " + currentContext.spPageContextInfo.aadTenantId);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment