Skip to content

Instantly share code, notes, and snippets.

@jorgenho
Created May 21, 2019 08:17
Show Gist options
  • Save jorgenho/1fedaf3274cdf7e90fc1a6097ce997ac to your computer and use it in GitHub Desktop.
Save jorgenho/1fedaf3274cdf7e90fc1a6097ce997ac to your computer and use it in GitHub Desktop.
office-js-helpers simple auth example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<!-- Office.js -->
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>
<!-- ES6 Shim of your choice -->
<script
src="https://cdnjs.cloudflare.com/ajax/libs/bluebird/3.3.4/bluebird.min.js"
class="pre"
></script>
<script src="https://unpkg.com/@microsoft/office-js-helpers@1.0.2/dist/office.helpers.js"></script>
<script>
Office.onReady(function() {
if (OfficeHelpers.Authenticator.isAuthDialog()) return;
var authenticator = new OfficeHelpers.Authenticator();
authenticator.endpoints.registerMicrosoftAuth(
"########-####-####-####-############",
{
redirectUrl: "{REDIRECT_URL}",
scope: "profile openid",
responseType: "id_token token"
}
);
authenticator
.authenticate(OfficeHelpers.DefaultEndpoints.Microsoft)
.then(function(token) {
document.querySelector("#root").innerHTML = JSON.stringify(token);
})
.catch(function(err) {
document.querySelector("#root").innerHTML = JSON.stringify(err);
});
});
</script>
</head>
<body>
<div id="root"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment