-
Notifications
You must be signed in to change notification settings - Fork 0
/
tester.html
112 lines (105 loc) · 3.37 KB
/
tester.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 lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Token Tester</title>
</head>
<body>
<h1>Token tester</h1>
<p>Login happens when the page is loaded. Change between a local test env or the rancher environment by editing this page's source.</p>
<p><a href="javascript:refresh()">Refresh your token</a></p>
<p><a href="javascript:logout()">Logout</a></p>
<p><a href="javascript:logoutAll()">Logout all</a></p>
<p><a href="javascript:inventorySearch()">Inventory search</a></p>
<script>
//If using folio-local-run
// var params = {
// host: "http://steve-host-2:9130",
// //loginEndpoint: "authn",
// loginEndpoint: "bl-users",
// credentials: { "username": "testing_admin", "password": "admin" },
// headers: {
// 'Content-type': 'application/json; charset=UTF-8',
// 'X-Okapi-Tenant': 'testlib14'
// }
// };
//If using rancher.
// var params = {
// host: "https://folio-dev-thunderjet-okapi.ci.folio.org",
// loginEndpoint: "bl-users",
// credentials: { "username": "", "password": "" },
// headers: {
// 'Content-type': 'application/json; charset=UTF-8',
// 'X-Okapi-Tenant': 'mobius'
// }
// };
// If using snapshot.
var params = {
host: "https://folio-snapshot-okapi.dev.folio.org",
loginEndpoint: "bl-users",
credentials: { "username": "diku_admin", "password": "" },
headers: {
'Content-type': 'application/json; charset=UTF-8',
'X-Okapi-Tenant': 'diku'
}
};
function inventorySearch() {
console.log("search inventory")
fetch(`${params.host}/search/instances?highlightMatch=true&limit=100&query=%28keyword%20all%20%22%2A%22%20or%20isbn%3D%22%2A%22%29%20sortby%20title`, {
method: 'GET',
credentials: 'include',
mode: 'cors',
headers: params.headers
})
.then(res => res.json())
.then(console.log)
}
function logout() {
console.log("logging out")
fetch(`${params.host}/authn/logout`, {
method: 'POST',
credentials: 'include',
mode: 'cors',
body: null,
headers: params.headers
});
}
function logoutAll() {
console.log("logout all")
fetch(`${params.host}/authn/logout-all`, {
method: 'POST',
credentials: 'include',
mode: 'cors',
body: null,
headers: params.headers
});
}
function refresh() {
console.log("refreshing token")
fetch(`${params.host}/authn/refresh`, {
method: 'POST',
credentials: 'include',
mode: 'cors',
body: null,
headers: params.headers
})
.then(res => res.json())
.then(console.log)
}
console.log("logging in and setting tokens");
fetch(`${params.host}/${params.loginEndpoint}/login-with-expiry`, {
method: 'POST',
// Absolutely have to have this specified here or the second request above won't work!
// https://stackoverflow.com/a/51726055
credentials: 'include',
mode: 'cors',
body: JSON.stringify(params.credentials),
headers: params.headers
})
.then(res => res.json())
.then(console.log)
</script>
</body>
</html>