Created
July 27, 2020 14:51
-
-
Save davecra/f271c3cd497af2f7354b7d299cc19c2a to your computer and use it in GitHub Desktop.
Gets the username for the current user using the SSO API
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
export async function getUserName() { | |
try { | |
let tokenData = await OfficeRuntime.auth.getAccessToken({ allowSignInPrompt: false, forMSGraphAccess: true }); | |
var parts = tokenData.split("."); | |
var token = JSON.parse(atob(parts[1])); | |
return token.preferred_username; | |
} | |
catch (exception) { | |
console.log(exception.message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment