@@ -67,39 +67,44 @@ export function initAdminCommon() {
6767 input . removeAttribute ( 'required' ) ;
6868 }
6969
70- const provider = document . getElementById ( 'oauth2_provider' ) ? .value ;
70+ const provider = document . getElementById ( 'oauth2_provider' ) . value ;
7171 switch ( provider ) {
7272 case 'openidConnect' :
73- for ( const input of document . querySelectorAll ( '.open_id_connect_auto_discovery_url input' ) ) {
74- input . setAttribute ( 'required' , 'required' ) ;
75- }
73+ document . querySelector ( '.open_id_connect_auto_discovery_url input' ) . setAttribute ( 'required' , 'required' ) ;
7674 showElem ( '.open_id_connect_auto_discovery_url' ) ;
7775 break ;
78- default :
79- if ( document . getElementById ( `#${ provider } _customURLSettings` ) ?. getAttribute ( 'data-required' ) ) {
80- document . getElementById ( 'oauth2_use_custom_url' ) ?. setAttribute ( 'checked' , 'checked' ) ;
76+ default : {
77+ const elProviderCustomUrlSettings = document . querySelector ( `#${ provider } _customURLSettings` ) ;
78+ if ( ! elProviderCustomUrlSettings ) break ; // some providers do not have custom URL settings
79+ const couldChangeCustomURLs = elProviderCustomUrlSettings . getAttribute ( 'data-available' ) === 'true' ;
80+ const mustProvideCustomURLs = elProviderCustomUrlSettings . getAttribute ( 'data-required' ) === 'true' ;
81+ if ( couldChangeCustomURLs ) {
82+ showElem ( '.oauth2_use_custom_url' ) ; // show the checkbox
8183 }
82- if ( document . getElementById ( `# ${ provider } _customURLSettings` ) ?. getAttribute ( 'data-available' ) ) {
83- showElem ( '. oauth2_use_custom_url') ;
84+ if ( mustProvideCustomURLs ) {
85+ document . querySelector ( '# oauth2_use_custom_url') . checked = true ; // make the checkbox checked
8486 }
87+ break ;
88+ }
8589 }
8690 onOAuth2UseCustomURLChange ( applyDefaultValues ) ;
8791 }
8892
8993 function onOAuth2UseCustomURLChange ( applyDefaultValues ) {
90- const provider = document . getElementById ( 'oauth2_provider' ) ? .value ;
94+ const provider = document . getElementById ( 'oauth2_provider' ) . value ;
9195 hideElem ( '.oauth2_use_custom_url_field' ) ;
9296 for ( const input of document . querySelectorAll ( '.oauth2_use_custom_url_field input[required]' ) ) {
9397 input . removeAttribute ( 'required' ) ;
9498 }
9599
96- if ( document . getElementById ( 'oauth2_use_custom_url' ) ?. checked ) {
100+ const elProviderCustomUrlSettings = document . querySelector ( `#${ provider } _customURLSettings` ) ;
101+ if ( elProviderCustomUrlSettings && document . getElementById ( 'oauth2_use_custom_url' ) . checked ) {
97102 for ( const custom of [ 'token_url' , 'auth_url' , 'profile_url' , 'email_url' , 'tenant' ] ) {
98103 if ( applyDefaultValues ) {
99104 document . getElementById ( `oauth2_${ custom } ` ) . value = document . getElementById ( `${ provider } _${ custom } ` ) . value ;
100105 }
101106 const customInput = document . getElementById ( `${ provider } _${ custom } ` ) ;
102- if ( customInput && customInput . getAttribute ( 'data-available' ) ) {
107+ if ( customInput && customInput . getAttribute ( 'data-available' ) === 'true' ) {
103108 for ( const input of document . querySelectorAll ( `.oauth2_${ custom } input` ) ) {
104109 input . setAttribute ( 'required' , 'required' ) ;
105110 }
0 commit comments