-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
65 lines (59 loc) · 2.29 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Swagger UI</title>
<link rel="stylesheet" type="text/css"
href="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/5.18.2/swagger-ui.css">
</head>
<body id="swagger-ui" style="margin: 0">
<script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/5.18.2/swagger-ui-bundle.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/5.18.2/swagger-ui-standalone-preset.js"></script>
<script>
window.onload = () => {
const ui = SwaggerUIBundle({
urls: [
{
url: "pikei.yaml",
name: "pikei"
}
],
dom_id: '#swagger-ui',
deepLinking: true,
oauth2RedirectUrl: window.location.origin + "/oauth2-redirect.html",
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout",
requestInterceptor: (req) => {
const token = localStorage.getItem('swagger_id_token');
if (token) {
req.headers.Authorization = `Bearer ${token}`;
}
return req;
}
});
// Listen for messages from oauth2-redirect.html
window.addEventListener("message", (event) => {
if (event.origin !== window.location.origin) {
console.error("Received message from unauthorized origin:", event.origin);
return;
}
if (event.data && event.data.access_token) {
console.log("Received OAuth tokens:", event.data);
// Store tokens for use in API requests
localStorage.setItem("swagger_access_token", event.data.access_token);
localStorage.setItem("swagger_id_token", event.data.id_token);
// Use the ID token (if needed)
document.getElementById('swagger-ui').setAttribute('data-oauth-token', event.data.id_token);
}
});
};
</script>
</body>
</html>