-
Notifications
You must be signed in to change notification settings - Fork 37
/
o4o.html
83 lines (77 loc) · 3.19 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
73
74
75
76
77
78
79
80
81
82
83
<title>OAuth for Okta</title>
<style>
body {
font-family: sans-serif;
width: 1100px;
margin: auto;
}
td {
padding: 1px 8px;
}
</style>
<body>
<h1>OAuth for Okta</h1>
<div id=version></div>
<br>
<div id=app>Loading...</div>
<script>
onload = async function () {
const paths = [];
const hash = {};
// Parse OpenAPI spec for paths.
const r = await fetch('https://raw.githubusercontent.com/okta/okta-management-openapi-spec/master/dist/spec.json');
const spec = await r.json();
for (const [path, methods] of Object.entries(spec.paths)) {
for (const method of Object.keys(methods)) {
paths.push({method, path});
hash[method + path.replace(/\{(.*?)\}/g, '{}')] = true;
}
}
version.innerHTML = `OpenAPI v. ${spec.info.version}`.link('https://github.com/okta/okta-management-openapi-spec') + ' ' + paths.length + ' paths.';
// Search docs for additional paths.
var url = 'https://api.github.com/search/code?q=repo:okta/okta-developer-docs+ApiOperation+extension:md';
while (url) {
const r = await fetch(url);
const page = await r.json();
if (!page.items.length) version.innerHTML += '<br>Unable to search https://github.com/okta/okta-developer-docs';
await Promise.all(page.items.filter(i => !i.path.match('/asa/')).map(async item => {
const r = await fetch('https://raw.githubusercontent.com/okta/okta-developer-docs/master/' + item.path);
const lines = (await r.text()).split('\n');
lines.forEach(line => {
if (match = line.match(/ApiOperation method="(.*?)" url="(.*?)"/)) {
var [, 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});
}
}
});
}));
url = r.headers.get('link')?.match('<(.*)>; rel="next"')?.[1];
}
const base = 'https://gsroka-neto.oktapreview.com';
const headers = {Authorization: 'Bearer invalidToken'};
paths.sort((p1, p2) => (p1.path + p1.method).localeCompare(p2.path + p2.method));
const 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';
}
if (path == '/api/v1/policies?type={type}') {
path = '/api/v1/policies?type=OKTA_SIGN_ON';
}
try {
const r = await fetch(base + path, {headers, method});
var scope = r.headers.get('www-authenticate').match(/scope="(.*?)"/)[1];
} catch (e) {
scope = '';
}
return `<tr><td>${method}<td>${path}<td>${scope}`;
}));
app.innerHTML = '<table><tr><th>Method<th>Path<th>Scope' + rows.join('') + '</table>';
};
</script>
</body>