-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
76 lines (64 loc) · 2.24 KB
/
index.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
'use strict';
angular.module('app', ['app.config'])
.config(['$locationProvider', function ($locationProvider) {
$locationProvider.html5Mode(false);
}])
.controller('main', ['$scope', '$http', '$window', '$location', '$httpParamSerializer', 'CONFIG' ,
($scope, $http, $window, $location, $httpParamSerializer, CONFIG) => {
$scope.action = "Login";
// login action
let login = () => {
var params =
{
client_id: CONFIG.client_id,
redirect_uri: CONFIG.redirect_uri,
response_type: 'token',
resource: "https://graph.windows.net/"
};
var query = $httpParamSerializer(params);
var loginUrl = CONFIG.authorization_endpoint + '?' + query;
$window.location.href = loginUrl;
};
// logout acion
let logout = () => {
$window.location.href = CONFIG.end_session_endpoint;
};
// handle button click event
$scope.click = (action) => {
if (action === 'Login') {
login();
}
else {
logout();
}
};
let result = {};
// Authorized
let hash = window.location.hash;
if (hash) {
$scope.action = "Logout";
// Parse url and get token.
hash.substr(2).split('&').map((value) => {
var data = value.split('=');
return {
[data[0]]: data[1]
}
}).forEach((value) => {
Object.assign(result, value);
});
// print token
$scope.decoded = jwt_decode(result.access_token);
// invoke graph api and print me
$http({
method: "GET",
url : "https://graph.windows.net/me?api-version=1.6",
headers: {
Authorization: "Bearer " + result.access_token
}
})
.then((response) =>{
$scope.me = response.data;
});
}
$scope.result = result;
}]);