blob: 513197c9a445e7576977f79e3f258203c028df6f (
plain)
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
|
window.END_SESSION_URL = "https://cri.epita.fr/end-session";
const reqInfosBtn = document.getElementById("RequestBtn");
const params = new URLSearchParams(window.location.search);
const code = params.get("code");
let form = new FormData();
form.append("client_id", "assistants-atelier-js");
form.append("redirect_uri", "http://localhost:8080/complete/epita/");
form.append("grant_type", "authorization_code");
form.append("code", code);
const tokenEndpoint = "http://localhost:8080/auth-api";
reqInfosBtn.addEventListener("click", async () => {
let response = await fetch(tokenEndpoint, {
method: "POST",
body: form,
});
const responsePretty = await response.json();
const token = responsePretty.id_token;
const content = token.split(".")[1];
const b64 = content.replace(/-/g, "+").replace(/_/g, "/");
const payload = JSON.parse(window.atob(b64));
document.getElementById("name").innerHTML = payload.name;
document.getElementById("campus").innerHTML = payload.zoneinfo;
document.getElementById("grad-year").innerHTML = payload.graduation_years;
document
.getElementById("image")
.setAttribute("src", payload.picture_square);
const ul = document.getElementById("list");
for (const group of payload.groups) {
const item = document.createElement("li");
item.innerHTML = group.slug + " " + group.name;
ul.appendChild(item);
}
});
document
.getElementById("EndBtn")
.addEventListener("click", () => window.location.replace(END_SESSION_URL));
|