-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[All Hosts] (snippets) Adding some high-value snippets (#2073)
* [All Hosts] (snippets) Adding some high-value snippets * Update docs/code-snippets/officeruntime-snippets.yaml
- Loading branch information
1 parent
a3f9fde
commit 9990ac8
Showing
3 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
OfficeRuntime.Auth:interface: | ||
- |- | ||
// Get the auth context object and use it to get an | ||
// access token. | ||
const authContext = OfficeRuntime.context.auth; | ||
const accessToken = authContext.getAccessTokenAsync(); | ||
Office.Auth#getAccessToken:member(1): | ||
- |- | ||
async function getUserData() { | ||
try { | ||
let userTokenEncoded = await OfficeRuntime.auth.getAccessToken(); | ||
let userToken = jwt_decode(userTokenEncoded); // Using the https://www.npmjs.com/package/jwt-decode library. | ||
console.log(userToken.name); // user name | ||
console.log(userToken.preferred_username); // email | ||
console.log(userToken.oid); // user id | ||
} | ||
catch (exception) { | ||
if (exception.code === 13003) { | ||
// SSO is not supported for domain user accounts, only | ||
// Microsoft 365 Education or work account, or a Microsoft account. | ||
} else { | ||
// Handle error | ||
} | ||
} | ||
} |
This file contains 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