-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.html
More file actions
417 lines (383 loc) · 18.5 KB
/
index.html
File metadata and controls
417 lines (383 loc) · 18.5 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
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="RERUM Authorization Portal">
<meta name="author" content="Research Computing Group, Saint Louis University">
<meta name="keywords" content="RERUM, Auth0, API, RESTful, compliant, open, free, attributed, versioned">
<title>RERUM Authorization Portal</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<style>
#msg {
color: green;
font-weight: bold;
}
#intro {
color: #979A9E;
font-size: 12pt;
}
body {
font-family: 'Open Sans', sans-serif;
color: #979A9E;
background-color: #2F353E;
}
input[type="text"] {
background-color: #ccc;
color: black;
font-weight: bold;
font-family: serif;
font-size: 14pt;
}
h1 {
cursor: pointer;
font-weight: 300;
font-family: 'Raleway', sans-serif;
margin-bottom: 10px;
}
.navbar-brand {
float: none;
font-size: 2rem;
line-height: 1.5;
margin-bottom: 20px;
}
#login {
display: none;
}
.panel-body {
color: initial;
}
.panel {
word-break: break-word;
}
.status_header {
color: gray;
}
#a_t {
height: 170px;
margin-bottom: 8px;
}
#a_t,
#r_t_4_a_t,
#new_refresh_token {
margin-bottom: 8px;
}
#code_for_refresh_token {
margin-bottom: -13px;
}
</style>
</head>
<body class="container">
<h1 onclick="window.location='https://rerum.io'" target="_blank" class="navbar-brand"><i class="fa fa-cubes"></i>
rerum</h1>
<div class='' id="intro">
<p>
We are so glad you are interested in using Saint Louis University's public object store, RERUM! Want to know
what RERUM is all about?
</p>
<ol type="1" id='rerumPrinciples'>
<li><strong>As RESTful as is reasonable—</strong>accept and respond to a broad range of requests without
losing the map</li>
<li><strong>As compliant as is practical—</strong>take advantage of standards and harmonize conflicts</li>
<li><strong>Save an object, retrieve an object—</strong>store metadata in private (__rerum) property, rather
than wrap all data transactions</li>
<li><strong>Trust the application, not the user—</strong>avoid multiple login and authentication
requirements and honor open data attributions</li>
<li><strong>Open and Free—</strong>expose all contributions immediately without charge to write or read</li>
<li><strong>Attributed and Versioned—</strong>always include asserted ownership and transaction metadata so
consumers can evaluate trustworthiness and relevance</li>
</ol>
</div>
<div class='panel panel-info' name="block">
<div class="panel-heading"> <span class="panel-title">Application Registration</span> </div>
<div class="panel-body">
<p class="handHoldy">
Interacting with RERUM requires server-to-server communication, so we suggest the registrant be the
application developer.
You may want to
<a target="_blank" rel="noopener" href="https://rerum.io/#/future"
class="linkOut">learn more about the concepts around RERUM</a>
before reading the API.
</p>
<p class="handHoldy">
If you are here for the first time and think you want to use RERUM, please
<a target="_blank" rel="noopener" href="https://store.rerum.io/API.html"
class="linkOut">read the API</a> first.
</p>
<p class="handHoldy">
If you like what you read in <a target="_blank" rel="noopener"
href="https://store.rerum.io/API.html"
class="linkOut">our API documentation</a>
and want to begin using RERUM as a back stack service please register by clicking below.
Be prepared to be routed to Auth0 (don't know why?
<a target="_blank" rel="noopener" href="https://store.rerum.io/API.html"
class="linkOut">Read the API</a>).
</p>
<p class="handHoldy">
After registering, you will be returned to this page with an Auth0 Authorization code. Use that code at
the bottom of this page to get a refresh token
and an access token so you can use the API. You may notice the page has already populated known
information for you.
</p>
</div>
<div class="panel-footer">
<input class='btn btn-primary btn-large' type="button" id="register" value="Register With RERUM At Auth0" />
</div>
</div>
<div class='panel panel-info' name="block">
<div class="panel-heading"> <span class="panel-title">Auth0 Authorization Status</span> </div>
<div class="panel-body">
<p class="handHoldy">
If you believe you are already registered and want to check on your status, follow the prompts below.
You will be routed to Auth0 so we can verify who you are.
</p>
<div>
<span class="status_header"> Auth0 Status </span>
<kbd class="rerumStatus" id="authorizationStatus">UNKNOWN</kbd>
</div>
</div>
<div class="panel-footer">
<input class='btn btn-primary btn-large' type="button" id="check_status"
value="Check my Authorization Status With Auth0" />
<!--<input class='btn btn-primary btn-large' type="button" id="login" value="Login To Get Auth Status" />-->
</div>
</div>
<div class='panel panel-info' name="block">
<div class="panel-heading"> <span class="panel-title">Test RERUM API Access</span> </div>
<div class="panel-body">
<p class="handHoldy">
Provide your access token below to check if it is still valid. If so, your access to RERUM will be
authorized. Otherwise, you will see an "unauthorized" message.
</p>
<p class="handHoldy">
If the token you have is not working, it may be because access tokens expire every 2 hours. You can use
your refresh token to get a new access token.
</p>
<textarea class="form-control" id="a_t" placeholder="Your access token goes here."></textarea>
<div>
<span class="status_header"> RERUM status </span>
<kbd class="rerumStatus" id="rerumStatus" class="">UNKNOWN</kbd>
</div>
</div>
<div class="panel-footer">
<input class='btn btn-primary btn-large' type="button" onclick="testAPI()" id="test_api"
value="Check Access To RERUM API" />
</div>
</div>
<div class='panel panel-info' name="block">
<div class="panel-heading"> <span class="panel-title">Get A New Access Token</span> </div>
<div class="panel-body">
<p class="handHoldy">
Your access token to use RERUM expires every 2 hours. Has it been that long or longer? Provide your
refresh token below to get a new access token.
If you lost your refresh token, you can get a new one in "Get A New Refresh Token" below.
</p>
<textarea class="form-control" placeholder="Your refresh token goes here." id="r_t_4_a_t"></textarea>
<div>
<span class="status_header"> Status </span>
<kbd class="rerumStatus" id="natStatus">UNKNOWN</kbd>
</div>
</div>
<div class="panel-footer">
<input class='btn btn-primary btn-large' type="button" id="request_token" value="Get A New Access Token" />
</div>
</div>
<div class='panel panel-info' name="block">
<div class="panel-heading"> <span class="panel-title">Get A New Refresh Token</span> </div>
<div class="panel-body">
<p class="handHoldy">
You can supply a valid Auth0 Authorization Code to get a new refresh token. Use "Check my Authorization
Status with Auth0" to get a valid code.
</p>
Enter your code: <textarea class="form-control" placeholder="Your Auth0 Authorization Code goes here"
id="code_for_refresh_token"></textarea>
<br>
<textarea readonly class="form-control" id="new_refresh_token"
placeholder="Your refresh token will appear here."></textarea>
<div>
<span class="status_header"> Status </span>
<kbd class="rerumStatus" id="nrtStatus">UNKNOWN</kbd>
</div>
</div>
<div class="panel-footer">
<input class='btn btn-primary btn-large' type="button" id="refresh_token" value="Get A New Refresh Token" />
</div>
</div>
<script type="text/javascript">
/*
* The process we are mimicking here is https://auth0.com/docs/api-auth/grant/authorization-code and
* https://auth0.com/docs/api-auth/tutorials/client-credentials
* https://auth0.com/docs/api-auth/tutorials/authorization-code-grant
* https://auth0.com/docs/api/authentication#authorization-code-grant
* https://auth0.com/docs/api-auth/grant/implicit
* https://auth0.com/docs/api-auth/grant/authorization-code
* https://auth0.com/docs/api-auth/tutorials/client-credentials
* TEST
*/
let access_token = ""
let auth_code = ""
let error_code = ""
let responseJSON = {}
const myURL = document.location.href
if (myURL.indexOf("access_token=") > -1) {
//The user registered or asked for a new token through the Client Credentials Grant flow https://auth0.com/docs/api-auth/tutorials/client-credentials
//Presumably, they had to come to rerum to do this. They cannot ask for new access tokens through their servers or front end.
access_token = getURLHash("access_token");
$("#test_api").show();
$("#a_t").val(access_token);
$("#check_status").hide();
$("#authorizationStatus").html("Thanks for choosing RERUM! A new token was created for you. Keep this token in a safe place, you will need it for our API. \n\
You can test that your access token will work with RERUM by clicking the 'Test API' button below. <br> token="+ access_token);
}
else if (myURL.indexOf("code=") > -1) {
//The user simply checked if they were registered. If so, they get a code. If not, they get an error.
auth_code = getURLVariable("code");
$("#code_for_refresh_token").val(auth_code);
if (auth_code !== "") {
$("#authorizationStatus").html("AUTHORIZED: auth code=" + auth_code + ". You are registered with the Auth0 RERUM client. Get a new refresh token using this code.");
}
else { //Weird
$("#authorizationStatus").html("UNAUTHORIZED");
}
$("#check_status").hide();
}
else if (myURL.indexOf("error=") > -1) {
//The user registered, checked their status or asked for a new access token and there was a problem.
error_code = getURLVariable("error");
if (error_code == "login_required") { //What they are asking for requires authentication against their user inside the RERUM Server Auth0 client.
$("#authorizationStatus").html("You must login with Auth0 for this check.");
$("#login").show();
}
else if (error_code == "consent_required") { //The user is logged in with auth0 but has not registered with the Rerum Server Auth0 client.
$("#authorizationStatus").html("You have never consented to use the API, so you do not have an access token. Get one to test access to RERUM.");
}
else if (error_code == "interaction_required") {
$("#authorizationStatus").html("There are strange happenings afoot in the void of the web...");
}
$("#check_status").hide();
}
else { //User came to web page, we don't know much about them.
}
$("#register").click(ev => fetch('/client/register').then(res => res.text()).then(url => location.href = url))// `https://cubap.auth0.com/authorize?response_type=code&client_id=62Jsa9MxHuqhRbO20gTHs9KpKr7Ue7sl&redirect_uri=http://store.rerum.io&state=STATE`)
$("#request_token").click(function () {
const refresh_token = $("#r_t_4_a_t").val()
if (!refresh_token) {
$("#r_t_4_a_t").attr("placeholder", "You must supply a refresh token here!")
$("#r_t_4_a_t").css("border", "2px solid yellow")
return false
}
fetch('/client/request-new-access-token', {
method: 'post',
headers: {
"Content-Type":"application/json; charset=utf-8"
},
body: JSON.stringify({ refresh_token })
}).then(resp => {
const statusElem = $("#natStatus");
if (resp.status < 300) {
statusElem.html("The refresh token was accepted.")
return resp.json()
} else {
$("#r_t_4_a_t").css("border", "2px solid red")
statusElem.html("The refresh token was invalid. Get a new refresh token or try again.")
return Promise.reject("Invalid refresh token.")
}
})
.then(token => {
$("#a_t").val(token.access_token)
})
})
$("#refresh_token").click(function () {
//The user would like to request a new access token using the refresh token. Send them off to log in.
const authorization_code = $("#code_for_refresh_token").val()
if (!authorization_code) {
$("#code_for_refresh_token").attr("placeholder", "You must supply a code here!")
$("#code_for_refresh_token").css("border", "2px solid yellow")
return false
}
$("#code_for_refresh_token").css("border", "none")
$("#new_refresh_token").css("border", "none")
$("#new_refresh_token").val("")
fetch('/client/request-new-refresh-token', {
method: 'post',
headers: {
"Content-Type":"application/json; charset=utf-8"
},
body: JSON.stringify({ authorization_code })
}).then(resp => {
const statusElem = $("#nrtStatus")
if (resp.status < 300) {
statusElem.html("Auth0 accepted the code.")
return resp.json()
} else {
$("#code_for_refresh_token").css("border", "2px solid red")
statusElem.html("Auth0 rejected the code. Check your status to get a new code and try again.")
return Promise.reject("Invalid authorization code.")
}
})
.then(token => {
$("#new_refresh_token").val(token.refresh_token)
$("#a_t").val(token.access_token)
})
})
$("#check_status").click(ev => {
fetch('/client/register')
.then(res => res.text())
.then(url =>
{
console.log(url)
location.href = url
})
})
// `https://cubap.auth0.com/authorize?response_type=code&client_id=62Jsa9MxHuqhRbO20gTHs9KpKr7Ue7sl&redirect_uri=http://store.rerum.io&state=STATE`)
function getURLVariable(variable) {
const query = window.location.search.substring(1);
const vars = query.split("&");
for (let i = 0; i < vars.length; i++) {
const pair = vars[i].split("=");
if (pair[0] == variable) { return pair[1]; }
}
return false;
}
function getURLHash(variable) {
let query = document.location.hash;
query = query.substr(1);
const vars = query.split("&");
for (let i = 0; i < vars.length; i++) {
const pair = vars[i].split("=");
if (pair[0] == variable) { return pair[1]; }
}
return false;
}
function testAPI() {
const userProvidedToken = $("#a_t").val()
if (!userProvidedToken) {
$("#a_t").attr("placeholder", "You must supply an access token here!")
$("#a_t").css("border", "2px solid yellow")
return false
}
$("#a_t").css("bordnser", "none"t)
const statusElem = $("#rerumStatus")
statusElem.html("WORKING...")
fetch('/client/verify', {
headers: {
Authorization: `Bearer ${userProvidedToken}`
}
})
.then(res => {
if (!res.ok) { throw Error("Catch me!") }
statusElem.html("AUTHORIZED")
$("#test_api").show()
})
.catch(err => {
statusElem.html("UNAUTHORIZED. Refresh your access token and try again. If you still have trouble, <a class='linkOut' href=''>contact us at RERUM</a>.")
$("#a_t").css("border", "2px solid red")
})
}
</script>
</body>
</html>