Skip to content

Instantly share code, notes, and snippets.

@davecra
Created July 27, 2020 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davecra/f271c3cd497af2f7354b7d299cc19c2a to your computer and use it in GitHub Desktop.
Save davecra/f271c3cd497af2f7354b7d299cc19c2a to your computer and use it in GitHub Desktop.
Gets the username for the current user using the SSO API
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