-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoauth.html
84 lines (75 loc) · 2.09 KB
/
oauth.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
72
73
74
75
76
77
78
79
80
81
82
83
84
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="config.js"></script>
<script src="swagger-js/browser/swagger-client.min.js"></script>
<script>
function getSearchObject(search) {
if (search === "") {
return {};
}
var o = {};
var nvPairs = search
.substr(1)
.replace(/\+/g, " ")
.split("&");
nvPairs.forEach(function(pair) {
var e = pair.indexOf("=");
var n = decodeURIComponent(e < 0 ? pair : pair.substr(0, e));
var v =
e < 0 || e + 1 == pair.length
? null
: decodeURIComponent(pair.substr(e + 1, pair.length - e));
if (!(n in o)) {
o[n] = v;
} else if (o[n] instanceof Array) {
o[n].push(v);
} else {
o[n] = [o[n], v];
}
});
return o;
}
var hash = window.location.hash.substring(1);
var parser = document.createElement("a");
parser.href = "oauth.html/?" + hash;
data = getSearchObject(parser.search);
if (sessionStorage.getItem("ngStorage-state") == '"' + data.state + '"') {
sessionStorage.setItem(
"ngStorage-access_token",
'"' + data.access_token + '"'
);
sessionStorage.setItem(
"ngStorage-expires_on",
'"' + (Date.now() + data.expires_in * 1000) + '"'
);
sessionStorage.setItem("ngStorage-hash", '"' + hash + '"');
sessionStorage.setItem("ngStorage-token_type", '"' + data.token_type + '"');
// Make a swagger client for the meta data endpoint
new SwaggerClient({
url: "https://esi.evetech.net/swagger.json?datasource=tranquility",
usePromise: true,
authorizations: {
evesso: new SwaggerClient.ApiKeyAuthorization(
"Authorization",
"Bearer " + data.access_token,
"header"
),
},
}).then(function(metaclient) {
// get characterId from verify
metaclient.Meta
.get_verify({})
.then(function(data) {
localStorage.setItem(
"ngStorage-characterId",
'"' + data.obj.CharacterID + '"'
);
window.location = BASE_URL + "/#!/authentication";
})
.catch(function(error) {
console.log(error);
});
});
} else {
document.write("Could not complete authentication.");
}
</script>