-
Notifications
You must be signed in to change notification settings - Fork 0
/
adl.html
71 lines (60 loc) · 2.64 KB
/
adl.html
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<html>
<head>
<title>PBI test</title>
</head>
<body>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://secure.aadcdn.microsoftonline-p.com/lib/1.0.0/js/adal.min.js"></script>
<script>
$(document).ready(function () {
/// PowerBI SharePoint WebPart
/// By Martin Laukkanen - TPG The Project Group
/// Including some of http://paulryan.com.au/2015/unified-api-adal/
/// v0.2.20161016
"use strict";
var config = {
tenant: 'orioninc.com',
clientId: 'd624bfd0-6ed9-4bb4-8548-6d70c76854d4',
redirectUri: 'http://localhost:9002/return.html',
postLogoutRedirectUri: window.location.origin,
prompt: 'none',
instance: 'https://login.windows.net/',
//endpoints: 'https://analysis.windows.net/powerbi/api',
resource: 'https://analysis.windows.net/powerbi/api',
cacheLocation: 'localStorage'
};
var authContext = new AuthenticationContext(config);
// Check For & Handle Redirect From AAD After Login
var isCallback = authContext.isCallback(window.location.hash);
authContext.handleWindowCallback();
if (isCallback && !authContext.getLoginError()) {
window.location = authContext._getItem(authContext.CONSTANTS.STORAGE.LOGIN_REQUEST);
}
// If not logged in force login
var user = authContext.getCachedUser(config.clientId);
console.log('user:');
console.log(user);
if (!user) {
authContext.login();
}
// Acquire token for resource.
authContext.acquireToken(config.resource, function (error, token) {
// Handle ADAL Errors.
if (error || !token) {
//if it fails with error AADSTS50058 which is caused due to how browser handles cookie
//then force user to go to login page again.
if(("" + error).indexOf("AADSTS50058") >= 0) {
authContext.login();
} else {
console.log('ADAL error occurred: ' + error);
return;
}
}
console.log(token);
// Store our token
config.authToken = token;
});
});
</script>
</html>