/
app.js
53 lines (45 loc) · 1.88 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(function ($) {
// Just a random helper to prettify json
function prettify(data) {
var json = JSON.stringify(data);
json = json.replace(/{/g, "{\n\n\t");
json = json.replace(/,/g, ",\n\t");
json = json.replace(/}/g, ",\n\n}");
return json;
}
$("document").ready(function () {
// Get the output pre
var output = $("#output");
// Determine if we are running inside of an authentication dialog
// If so then just terminate the running function
if (OfficeHelpers.Authenticator.isAuthDialog()) {
// Adding code here isn"t guaranteed to run as we need to close the dialog
// Currently we have no realistic way of determining when the dialog is completely
// closed.
output.text("Closing AuthDialog...");
return;
}
// Create a new instance of Authenticator
var authenticator = new OfficeHelpers.Authenticator();
// Register our providers accordingly
authenticator.endpoints.registerAzureADAuth("CLIENT_ID_GUID_HERE", "TENANT_ID_GUID_HERE", {
redirectUrl: 'https://your_domain.com/index.html',
resource: 'https://graph.microsoft.com'
});
// Authenticate with the chosen provider
authenticator.authenticate(OfficeHelpers.DefaultEndpoints.AzureAD, true /* setting the force to true, always re-authenticates. This is just for demo purposes */)
.then(function (token) {
// Consume the acess token
output.text(prettify(token));
})
.catch(function (error) {
// Handle the error
output.text(prettify(error));
});
// Add event handlers to the buttons
$(".login").click(function () {
var token = authenticator.tokens.get(OfficeHelpers.DefaultEndpoints.AzureAD);
output.text("Token Info: " + prettify(token));
});
});
})(jQuery);