Fix admin oauth2 custom URL settings (#31246)

Fix #31244
This commit is contained in:
wxiaoguang 2024-06-04 23:06:21 +08:00 коммит произвёл GitHub
Родитель 138e946c3d
Коммит fcc061ae44
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 17 добавлений и 12 удалений

Просмотреть файл

@ -67,39 +67,44 @@ export function initAdminCommon() {
input.removeAttribute('required'); input.removeAttribute('required');
} }
const provider = document.getElementById('oauth2_provider')?.value; const provider = document.getElementById('oauth2_provider').value;
switch (provider) { switch (provider) {
case 'openidConnect': case 'openidConnect':
for (const input of document.querySelectorAll('.open_id_connect_auto_discovery_url input')) { document.querySelector('.open_id_connect_auto_discovery_url input').setAttribute('required', 'required');
input.setAttribute('required', 'required');
}
showElem('.open_id_connect_auto_discovery_url'); showElem('.open_id_connect_auto_discovery_url');
break; break;
default: default: {
if (document.getElementById(`#${provider}_customURLSettings`)?.getAttribute('data-required')) { const elProviderCustomUrlSettings = document.querySelector(`#${provider}_customURLSettings`);
document.getElementById('oauth2_use_custom_url')?.setAttribute('checked', 'checked'); if (!elProviderCustomUrlSettings) break; // some providers do not have custom URL settings
const couldChangeCustomURLs = elProviderCustomUrlSettings.getAttribute('data-available') === 'true';
const mustProvideCustomURLs = elProviderCustomUrlSettings.getAttribute('data-required') === 'true';
if (couldChangeCustomURLs) {
showElem('.oauth2_use_custom_url'); // show the checkbox
} }
if (document.getElementById(`#${provider}_customURLSettings`)?.getAttribute('data-available')) { if (mustProvideCustomURLs) {
showElem('.oauth2_use_custom_url'); document.querySelector('#oauth2_use_custom_url').checked = true; // make the checkbox checked
} }
break;
}
} }
onOAuth2UseCustomURLChange(applyDefaultValues); onOAuth2UseCustomURLChange(applyDefaultValues);
} }
function onOAuth2UseCustomURLChange(applyDefaultValues) { function onOAuth2UseCustomURLChange(applyDefaultValues) {
const provider = document.getElementById('oauth2_provider')?.value; const provider = document.getElementById('oauth2_provider').value;
hideElem('.oauth2_use_custom_url_field'); hideElem('.oauth2_use_custom_url_field');
for (const input of document.querySelectorAll('.oauth2_use_custom_url_field input[required]')) { for (const input of document.querySelectorAll('.oauth2_use_custom_url_field input[required]')) {
input.removeAttribute('required'); input.removeAttribute('required');
} }
if (document.getElementById('oauth2_use_custom_url')?.checked) { const elProviderCustomUrlSettings = document.querySelector(`#${provider}_customURLSettings`);
if (elProviderCustomUrlSettings && document.getElementById('oauth2_use_custom_url').checked) {
for (const custom of ['token_url', 'auth_url', 'profile_url', 'email_url', 'tenant']) { for (const custom of ['token_url', 'auth_url', 'profile_url', 'email_url', 'tenant']) {
if (applyDefaultValues) { if (applyDefaultValues) {
document.getElementById(`oauth2_${custom}`).value = document.getElementById(`${provider}_${custom}`).value; document.getElementById(`oauth2_${custom}`).value = document.getElementById(`${provider}_${custom}`).value;
} }
const customInput = document.getElementById(`${provider}_${custom}`); const customInput = document.getElementById(`${provider}_${custom}`);
if (customInput && customInput.getAttribute('data-available')) { if (customInput && customInput.getAttribute('data-available') === 'true') {
for (const input of document.querySelectorAll(`.oauth2_${custom} input`)) { for (const input of document.querySelectorAll(`.oauth2_${custom} input`)) {
input.setAttribute('required', 'required'); input.setAttribute('required', 'required');
} }