Created
March 12, 2020 10:18
-
-
Save ktskumar/f4c5acfa0a5ee0e8066672ed61c9db99 to your computer and use it in GitHub Desktop.
How to get Current User AAD ID and Tenant ID from SharePoint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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