2022-01-23 07:31:40 +13:00
|
|
|
(function (window) {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
//TODO: Make this generic
|
|
|
|
|
|
|
|
window.ls.container.get("view").add({
|
|
|
|
selector: "data-forms-oauth-custom",
|
|
|
|
controller: function (element) {
|
|
|
|
// provider configuration for custom forms. Keys will be property names in JSON, values the elementIDs for the according inputs
|
|
|
|
let providers = {
|
|
|
|
"Microsoft": {
|
|
|
|
"clientSecret": "oauth2MicrosoftClientSecret",
|
2022-04-03 02:12:31 +13:00
|
|
|
"tenantID": "oauth2MicrosoftTenantId"
|
2022-01-23 11:13:16 +13:00
|
|
|
},
|
|
|
|
"Apple": {
|
2022-04-03 02:12:31 +13:00
|
|
|
"keyID": "oauth2AppleKeyId",
|
|
|
|
"teamID": "oauth2AppleTeamId",
|
2022-01-23 11:13:16 +13:00
|
|
|
"p8": "oauth2AppleP8"
|
2022-04-24 06:14:32 +12:00
|
|
|
},
|
|
|
|
"Okta": {
|
|
|
|
"clientSecret": "oauth2OktaClientSecret",
|
2022-04-26 22:15:42 +12:00
|
|
|
"oktaDomain": "oauth2OktaDomain",
|
|
|
|
"authorizationServerId": "oauth2OktaAuthorizationServerId"
|
2022-04-27 02:10:54 +12:00
|
|
|
},
|
2022-04-01 23:34:56 +13:00
|
|
|
"Auth0": {
|
|
|
|
"clientSecret": "oauth2Auth0ClientSecret",
|
|
|
|
"auth0Domain": "oauth2Auth0Domain"
|
2022-01-23 07:31:40 +13:00
|
|
|
}
|
|
|
|
}
|
|
|
|
let provider = element.getAttribute("data-forms-oauth-custom");
|
2022-04-24 09:29:26 +12:00
|
|
|
if (!provider || !providers.hasOwnProperty(provider)) { console.error("Provider for custom form not set or unknown") }
|
2022-01-23 07:31:40 +13:00
|
|
|
let config = providers[provider];
|
|
|
|
|
|
|
|
// Add Change Listeners for element
|
|
|
|
element.addEventListener('change', sync);
|
|
|
|
|
|
|
|
// Get all inputs by id and register change event listener
|
|
|
|
let elements = {};
|
|
|
|
for (const key in config) {
|
|
|
|
if (Object.hasOwnProperty.call(config, key)) {
|
|
|
|
elements[key] = document.getElementById(config[key]);
|
|
|
|
elements[key].addEventListener('change', update);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Build the JSON based on input in custom input fields
|
|
|
|
function update() {
|
|
|
|
let json = {};
|
|
|
|
for (const key in elements) {
|
|
|
|
if (Object.hasOwnProperty.call(elements, key)) {
|
|
|
|
json[key] = elements[key].value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
element.value = JSON.stringify(json);
|
|
|
|
}
|
|
|
|
|
|
|
|
// When the JSON changes (on load) change values in custom input fields
|
|
|
|
function sync() {
|
|
|
|
if (!element.value) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let json = {};
|
|
|
|
|
|
|
|
try {
|
|
|
|
json = JSON.parse(element.value);
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Failed to parse secret key');
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const key in elements) {
|
|
|
|
if (Object.hasOwnProperty.call(elements, key)) {
|
|
|
|
elements[key].value = json[key] || '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sync();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})(window);
|