forked from gabrielsroka/gabrielsroka.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
o4o.html
72 lines (68 loc) · 2.69 KB
/
o4o.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
<title>OAuth for Okta</title>
<style>
body {
font-family: sans-serif;
width: 1100px;
margin: auto;
}
td {
padding: 1px 8px;
}
</style>
<h1>OAuth for Okta</h1>
<div id=app>Loading...</div>
<script>
onload = async function () {
paths = []
hash = {}
r = await fetch('https://raw.githubusercontent.com/okta/okta-sdk-java/master/src/swagger/api.yaml')
lines = (await r.text()).split('\n')
lines.forEach(line => {
if (match = line.match(/^ '?(\/.*?)'?:/)) {
path = match[1]
} else if (match = line.match(/^ (get|post|put|delete)/)) {
method = match[1]
paths.push({method, path})
hash[method + path.replace(/\{(.*?)\}/g, '{}')] = true
} else if (match = line.match(/^ version: (.*)/)) {
version = match[1]
}
})
r = await fetch('https://api.github.com/search/code?q=repo:okta/okta-developer-docs ApiOperation extension:md');
page = await r.json()
await Promise.all(page.items.map(async item => {
r = await fetch('https://raw.githubusercontent.com/okta/okta-developer-docs/master/' + item.path)
lines = (await r.text()).split('\n')
lines.forEach(line => {
if (match = line.match(/ApiOperation method="(.*?)" url="(.*?)"/)) {
[_, method, path] = match
method = method.toLowerCase()
path = path.replace(/\${/g, '{').replace('{baseUrl}', '').replace('https://{yourOktaDomain}', '').trim()
if (path.startsWith('/v1')) path = '/api' + path
if (!hash[method + path.replace(/\{(.*?)\}/g, '{}')]) {
paths.push({method, path})
}
}
})
}))
base = 'https://gsroka-neto.oktapreview.com'
headers = {Authorization: 'Bearer invalidToken'}
paths.sort((p1, p2) => (p1.path + p1.method).localeCompare(p2.path + p2.method))
rows = await Promise.all(paths.map(async ({method, path}) => {
if (path == '/api/v1/idps/{idpId}/credentials/csrs/{csrId}/lifecycle/publish') {
headers['content-type'] = 'application/pkix-cert'
} else {
headers['content-type'] = 'application/json'
}
try {
r = await fetch(base + path, {headers, method})
scope = r.headers.get('www-authenticate').match(/scope="(.*?)"/)[1]
} catch (e) {
scope = ''
}
return `<tr><td>${method}<td>${path}<td>${scope}<td>${r.status}`
}))
app.innerHTML = `<a href="https://github.com/okta/okta-sdk-java/blob/master/src/swagger/api.yaml">Swagger v. ${version}</a>` +
'<table><tr><th>Method<th>Path<th>Scope<th>Status' + rows.join('') + '</table>'
}
</script>