forked from Root-1/flashcards
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoauth_redirect.html
39 lines (37 loc) · 1.32 KB
/
oauth_redirect.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
<html>
<title>Connecting to OpenMinds</title>
<body>
<script>
// Parses the access token from the URL and passes it to the
// opening page.
// Then, calls window.close() to close the popup.
// NOTE(adam): Safari does not properly detect when a popup window
// is closed. Thus, we set om.windowClosed on the main app page,
// so that the main app is aware that the popup window is gone.
var opener = window.opener;
var params = {};
var parameters = window.location.search.slice(1).split('&');
for (var i = 0; i < parameters.length; ++i) {
var p = parameters[i].split('=');
params[p[0]] = decodeURIComponent(p[1]);
}
if (params.error) {
document.body.innerHTML = (
'<h2>' + params.error + '</h2>');
if (params.error_description) {
document.body.innerHTML += ('<h3>' + params.error_description + '</h>');
}
} else {
var accessTokenRegExp = new RegExp('#access_token=([^&]*)');
var accessTokenMatch = window.location.hash.match(accessTokenRegExp);
if (accessTokenMatch && accessTokenMatch.length == 2) {
window.localStorage.setItem('omAccessToken', accessTokenMatch[1]);
if (opener && opener.om) {
opener.om.windowClosed = true;
}
window.close();
}
}
</script>
</body>
</html>