forked from gabrielsroka/gabrielsroka.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateSAMLCert.js
70 lines (65 loc) · 2.19 KB
/
updateSAMLCert.js
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
/*
Update the certificate for a SAML app. See:
https://developer.okta.com/docs/guides/updating-saml-cert
Setup:
Copy this code to the browser console or, if using Chrome, to a Snippet. For example:
1. Press F12 (Windows) to open DevTools.
2. Go to Sources > Snippets, click New Snippet.
3. Give it a name, eg, "updateSAMLCert.js".
4. Copy/paste the code from https://gabrielsroka.github.io/updateSAMLCert.js
5. Save (Ctrl+S, Windows).
Usage:
1. In Okta Admin, go to Applications > Applications and click on an app.
2. Press F12 (Windows) to open DevTools.
3. Run the code. If using a Snippet, there's a Run button on the bottom right, or press Ctrl+Enter (Windows).
*/
(async function () {
var appId = getAppId();
if (!appId) {
alert("Error. Go to Applications > Applications and click on an app.");
return;
}
while (true) {
var validityYears = prompt("Enter years of validity. This must be between 2 and 10.", 10);
if (validityYears) {
if (validityYears >= 2 && validityYears <= 10) {
break;
} else {
alert("Invalid value.");
}
} else {
return;
}
}
try {
var app = await $.get("/api/v1/apps/" + appId);
var key = await $.post("/api/v1/apps/" + appId + "/credentials/keys/generate?validityYears=" + validityYears);
var updatedApp = {
name: app.name,
label: app.label,
signOnMode: app.signOnMode,
credentials: {
signing: {
kid: key.kid
}
}
};
await put("/api/v1/apps/" + appId, updatedApp);
location = "/admin/org/security/" + appId + "/cert";
} catch (jqXHR) {
alert("Error: " + jqXHR.responseJSON.errorCauses.map(e => e.errorSummary).join("\n"));
}
function put(url, body) {
return $.ajax({
type: "PUT",
url: url,
data: JSON.stringify(body),
contentType: "application/json"
});
}
function getAppId() {
if (location.pathname.match("/admin/app/")) {
return location.pathname.split("/")[5];
}
}
})();