-
Notifications
You must be signed in to change notification settings - Fork 595
/
Copy pathgithub-classroom-redirect.html
112 lines (101 loc) · 4.73 KB
/
github-classroom-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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://ogp.me/ns#" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<meta charset="UTF-8">
<title>MakeCode GitHub Classroom Registration</title>
<link rel="stylesheet"
href="https://cdn.makecode.com/blob/2163189fd5e35c0981ed55318415582a7c9aeb12/doccdn/semantic.css"
type="text/css">
<script>
(function () {
let keys = {};
function log(msg) {
const eel = document.getElementById("log");
const line = document.createElement("div");
line.className = "ui message"
line.innerText = msg;
eel.append(line);
}
function signIn() {
const state = Math.random().toString();
const assignment = keys["assignment"];
localStorage["core/oauthState"] = state;
localStorage["core/ghclassroomassigment"] = assignment;
const login = "https://makecode.com/oauth/login?state=" + state +
"&prompt=consent&response_type=token&client_id=gh-token&redirect_uri=" + encodeURIComponent(window.location.href.split('#', 1)[0])
window.location.href = login;
}
function redirectGithub() {
if (!keys["state"] || keys["state"] != localStorage["core/oauthState"]) {
delete localStorage["core/oauthState"];
delete localStorage["core/ghclassroomassigment"];
throw new Error("invalid query");
}
const assignment = localStorage["core/ghclassroomassigment"];
// do not store access token as the user has not explicitely allow storage
// localStorage["core/githubtoken"] = keys["access_token"];
delete localStorage["core/oauthState"];
delete localStorage["core/ghclassroomassigment"];
var url = "https://classroom.github.com/" + assignment;
log(`Redirecting to GitHub Classroom...`);
setTimeout(() => window.location.href = url, 2000);
}
function init() {
// sniff oauth
window.location.hash.replace(/^#/, '').split('&')
.map(v => v.split('=', 2))
.forEach(a => keys[a[0]] = a[1]);
if (keys["access_token"]) {
redirectGithub()
} else {
// we've been asked for an assignment,
const assignment = keys["assignment"];
if (!assignment)
throw Error("Invalid query");
document.getElementById("signinbtn").onclick = () => signIn();
document.getElementById("signin").className = "";
}
}
window.addEventListener("load", function () {
try {
init();
} catch (e) {
log(`error: ${e.message}`)
throw e; // for tracking
}
});
})();
</script>
</head>
<body id='root' class='root'>
<div class="ui container">
<h1>
MakeCode for GitHub Classroom Registration
</h1>
<div id="signin" class="ui segment hidden">
<p>
In order to use <a href="https://makecode.com" target="_blank">Microsoft MakeCode</a> with <a
href="https://classroom.github.com" target="_blank">GitHub Classroom</a>,
you need to <strong>grant access</strong> to the
<a href="https://github.com/settings/connections/applications/1919c4da46b6e87c4469"
target="_blank">Microsoft MakeCode for GitHub</a> app
to your classroom organization.
</p>
<p>
<button class="ui green button" id="signinbtn">Authorize Microsoft MakeCode for GitHub</button>
</p>
</div>
<p id="log">
</p>
<footer id="footer" class="hideprint">
<a class="item" href="https://makecode.com/privacy" target="_blank" rel="noopener">Privacy & Cookies</a>
<a class="item" href="https://makecode.com/termsofuse" target="_blank" rel="noopener"> Terms Of Use</a>
<a class="item" href="https://makecode.com/trademarks" target="_blank" rel="noopener">Trademarks</a>
<div class="item">© 2022 Microsoft</div>
</footer>
</div>
<script type="text/javascript"
src="https://cdn.makecode.com/blob/795d8506c80a04f5ca26f577a8d6152e2fa3e7a6/doccdn/pxtweb.js"></script>
<!-- @include tracking.html -->
</body>
</html>