-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
210 lines (161 loc) · 5.11 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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<!DOCTYPE html>
<html>
<head>
<title>Site Surveyor</title>
<meta charset="UTF-8">
<link rel="icon" href="data:,">
<link rel="stylesheet" href="https://edwardtufte.github.io/tufte-css/tufte.css"/>
<!--
<link rel="stylesheet" href="https://unpkg.com/@picocss/pico@1.*/css/pico.min.css">
-->
<script src="https://unpkg.com/htmx.org@1.8.5"
integrity="sha384-7aHh9lqPYGYZ7sTHvzP1t3BAfLhYSTy9ArHdP3Xsr9/3TlGurYgcPBoFmXX2TX/w"
crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
<style>
table {
border: 1px solid black;
border-collapse: collapse;
}
table td {
border: 1px solid black;
padding: 2pt;
}
img {
box-shadow: -5px 5px 5px -5px rgba(80, 80, 80);
margin: 0 1em;
}
</style>
</head>
<body>
<main
x-data="{authServer: 'https://auth.site.test',
apiServer: 'https://data.site.test'
}"
class="container">
<img style="float: right" src="surveyor.jpg">
<h1>Site Surveyor</h1>
<p>Welcome to Site Surveyor!
This is a website that talks to your Site instance.</p>
<h3>Authorize</h3>
<p>Before we can continue, we must first acquire an <b>access token</b> which will be used to access your Site instance's resources.</p>
<div>
<p>First, let's configure the location of your authorization server.</p>
<p>
<label for="authServer">OAuth2 Authorization Server</label>
<input id="authServer" x-model="authServer"
placeholder="Authorization Server...">
</p>
<p>Click
<a :href="authServer + '/oauth/authorize?client_id=surveyor&response_type=token'">here</a>
to get your token!</p>
<p>
<label for="access-token">Access Token</label>
<input id="access-token">
</p>
<p>Finally we need to know the host serving the Site API:</p>
<p>
<label for="apiServer">API Server</label>
<input id="apiServer" x-model="apiServer"
placeholder="API Server...">
</p>
</div>
<br style="clear: both">
<section>
<h2>Operations</h2>
<div class="epigraph">
<blockquote>
For every action, there is an equal and opposite reaction.
<footer>Isaac Newton</footer>
</blockquote>
</div>
<p style="display: none">
Until we acquire an <i>access token</i>, these will be just the 'public' operations!
</p>
<figure class="fullwidth">
<h3>List of Operations</h3>
<p>This list is available from <a href="https://swagger-ui.site.test/#/Operations" x-text="apiServer + '/_site/operations'"></a></p>
<div class="authorized"
:hx-get="apiServer + '/_site/operations'"
hx-trigger="load">
<code>
Loading operations...
</code>
</div>
</figure>
<p id="bar">Click HERE to print a list of operations onto the console!</p>
</section>
<section>
<h2>Users</h2>
<p>TODO: Show a whole tree of a selected user, including identities and access-tokens.</p>
<!--
<figure class="fullwidth">
<h3>List of Users</h3>
<p>The list of users is available
from <a href="https://swagger-ui.site.test/#/Users"
x-text="apiServer + '/_site/users'"></a></p>
<div class="authorized"
:hx-get="apiServer + '/_site/users'"
hx-trigger="load">
<code>
Loading users...
</code>
<aside>(note: this won't complete until we have authorization working!)</aside>
</div>
</figure>
-->
<!--
<h3>mal</h3>
<div class="authorized" :hx-get="apiServer + '/users/mal'" hx-trigger="load">
<code>
Loading mal...
</code>
</div>
-->
</section>
<div class="flex-center full-height">
<div class="content">
<a href="#" id="start">Click to Sign In</a>
<div id="token" class="hidden">
<h2>Access Token</h2>
<div id="access_token" class="code"></div>
</div>
<div id="error" class="hidden">
<h2>Error</h2>
<div id="error_details" class="code"></div>
</div>
</div>
</div>
<p id="foo">Click HERE to get access token</p>
</main>
<script type="module">
import { useOAuth2 } from "./oauth2.js";
const { sendAuthTokenRequest, isError, sendAuthCodeRequest } = useOAuth2({
client_id: "surveyor",
authorization_endpoint: "https://auth.site.test/oauth/authorize",
token_endpoint: "https://auth.site.test/oauth/token",
redirect_uri: "https://surveyor.site.test/index.html",
requested_scopes: "",
protected_hostname: "data.site.test",
protected_pathname: "/*",
});
document.getElementById("foo").addEventListener("click", sendAuthCodeRequest);
document.getElementById("bar").addEventListener("click", async () =>
{
const response = await fetch("https://data.site.test/_site/operations",
{ method: 'GET', headers: {"accept": "application/json"}})
const data = await response.json();
console.dir(data);
;
});
if (isError) {
alert("ERROR");
} else {
sendAuthTokenRequest(
(data) => console.log("authenticated"),
(error) => {console.log("ERROR"); console.dir(error); }
);
}
</script>
</body>
</html>