forked from Erkan-Yilmaz/ToS-DR
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-connect.html
More file actions
51 lines (51 loc) · 1.6 KB
/
github-connect.html
File metadata and controls
51 lines (51 loc) · 1.6 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf8" />
<title>experimental! form for submitting data points</title>
</head>
<body>
<p>
<a href="https://github.com/login/oauth/authorize?client_id=3365a610f873704cff3a">log in with github</a>
</p>
<p>this page is still under construction (check the console)</p>
</body>
<script>
var githubClient = {
id: '3365a610f873704cff3a',
secret: 'e9b3c5161bf15a2518046e95d64efc880afcfc58',
proxy1: 'https://cors.5apps.com/?uri=https://github.com',
proxy2: 'https://cors.5apps.com/?uri=https://api.github.com'
};
function post(path, payload, cb) {
var xhr = new XMLHttpRequest();
xhr.open('POST', githubClient.proxy1+path, true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.setRequestHeader('Content-Length', payload.length);
xhr.onload = function () {
console.log(xhr.status);
console.log(xhr.responseText);
}
xhr.send(payload);
}
function extractParam(key) {
var pairs = location.search.substring(1).split('&');
for(var i=0; i<pairs.length; i++) {
var kv = pairs[i].split('=');
if(decodeURIComponent(kv[0])==key) {
return decodeURIComponent(kv[1]);
}
}
}
function codeToToken() {
var code = extractParam('code');
if(code) {
post('/login/oauth/access_token',
'client_id='+githubClient.id+'&client_secret='+githubClient.secret
+'&code='+code, function(){
});
}
}
codeToToken();
</script>
</html>