forked from coppersalts/HTML5b
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthredirect.html
57 lines (55 loc) · 2.23 KB
/
authredirect.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Discord Auth Redirect</title>
<script type="text/javascript">
function saveTokens() {
// TODO: add checks to make sure the query string is actually there before saving the things.
const params = new URLSearchParams(window.location.search);
// localStorage.setItem('access_token', params.get('access_token'));
// localStorage.setItem('refresh_token', params.get('refresh_token'));
document.cookie = 'token_created_at=' + Date.now() + '; path=/';
document.cookie = 'access_token=' + params.get('access_token') + '; path=/';
document.cookie = 'refresh_token=' + params.get('refresh_token') + '; path=/';
// browser.cookies.set({domain:'coppersalts.github.io',httpOnly:true,name:'access_token',url:'/',value:params.get('access_token')});
// browser.cookies.set({domain:'coppersalts.github.io',httpOnly:true,name:'refresh_token',url:'/',value:params.get('refresh_token')});
window.close();
getCurrentExploreUserID();
}
/*function getCurrentExploreUserID() {
return fetch('https://discord.com/api/v10/users/@me', {
method: 'GET',
headers: {'Authorization': 'Bearer ' + getCookie('access_token')}
}).then(async indentity => {
const discordId = (await indentity.json()).id;
fetch('https://5beam.zelo.dev/api/user?discordId=' + discordId, {method: 'GET'})
.then(async response => {
loggedInExploreUser5beamID = (await response.json()).id;
document.cookie = '5beam_id=' + loggedInExploreUser5beamID + '; path=/';
}).catch(err => {console.log(err);});
}).catch(err => {console.log(err)});
}
// https://www.w3schools.com/js/js_cookies.asp
function getCookie(cname) {
let name = cname + '=';
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return '';
}*/
</script>
</head>
<body onload="saveTokens()">
<p>If this window doesn't close automatically, you can just close it yourself.</p>
</body>
</html>