|
384 | 384 | var auth_settings_access_redirect_to_login = $( '#radio_auth_settings_access_redirect_to_login' ).closest( 'tr' ); |
385 | 385 | var auth_settings_access_public_warning = $( '#radio_auth_settings_access_public_warning' ).closest( 'tr' ); |
386 | 386 | var auth_settings_access_redirect_to_message = $( '#wp-auth_settings_access_redirect_to_message-wrap' ).closest( 'tr' ); |
387 | | - var auth_settings_external_oauth2_provider = $( '#auth_settings_oauth2_provider' ).closest( 'tr' ); |
388 | | - var auth_settings_external_oauth2_custom_label = $( '#auth_settings_oauth2_custom_label' ).closest( 'tr' ); |
389 | | - var auth_settings_external_oauth2_clientid = $( '#auth_settings_oauth2_clientid' ).closest( 'tr' ); |
390 | | - var auth_settings_external_oauth2_clientsecret = $( '#auth_settings_oauth2_clientsecret' ).closest( 'tr' ); |
391 | | - var auth_settings_external_oauth2_hosteddomain = $( '#auth_settings_oauth2_hosteddomain' ).closest( 'tr' ); |
392 | | - var auth_settings_external_oauth2_tenant_id = $( '#auth_settings_oauth2_tenant_id' ).closest( 'tr' ); |
393 | | - var auth_settings_external_oauth2_url_authorize = $( '#auth_settings_oauth2_url_authorize' ).closest( 'tr' ); |
394 | | - var auth_settings_external_oauth2_url_token = $( '#auth_settings_oauth2_url_token' ).closest( 'tr' ); |
395 | | - var auth_settings_external_oauth2_url_resource = $( '#auth_settings_oauth2_url_resource' ).closest( 'tr' ); |
396 | | - var auth_settings_external_oauth2_attr_username = $( '#auth_settings_oauth2_attr_username' ).closest( 'tr' ); |
397 | | - var auth_settings_external_oauth2_attr_email = $( '#auth_settings_oauth2_attr_email' ).closest( 'tr' ); |
398 | | - var auth_settings_external_oauth2_attr_first_name = $( '#auth_settings_oauth2_attr_first_name' ).closest( 'tr' ); |
399 | | - var auth_settings_external_oauth2_attr_last_name = $( '#auth_settings_oauth2_attr_last_name' ).closest( 'tr' ); |
400 | | - var auth_settings_external_oauth2_attr_update_on_login = $( '#auth_settings_oauth2_attr_update_on_login' ).closest( 'tr' ); |
401 | 387 | var auth_settings_external_oauth2_auto_login = $( '#auth_settings_oauth2_auto_login' ).closest( 'tr' ); |
| 388 | + var auth_settings_external_oauth2_num_servers = $( '#auth_settings_oauth2_num_servers' ).closest( 'tr' ); |
| 389 | + var auth_settings_external_oauth2_servers = []; |
| 390 | + // OAuth2 settings below are for the first configured OAuth2 server. |
| 391 | + auth_settings_external_oauth2_servers.push( { |
| 392 | + provider: $( '#auth_settings_oauth2_provider' ).closest( 'tr' ), |
| 393 | + custom_label: $( '#auth_settings_oauth2_custom_label' ).closest( 'tr' ), |
| 394 | + clientid: $( '#auth_settings_oauth2_clientid' ).closest( 'tr' ), |
| 395 | + clientsecret: $( '#auth_settings_oauth2_clientsecret' ).closest( 'tr' ), |
| 396 | + hosteddomain: $( '#auth_settings_oauth2_hosteddomain' ).closest( 'tr' ), |
| 397 | + tenant_id: $( '#auth_settings_oauth2_tenant_id' ).closest( 'tr' ), |
| 398 | + url_authorize: $( '#auth_settings_oauth2_url_authorize' ).closest( 'tr' ), |
| 399 | + url_token: $( '#auth_settings_oauth2_url_token' ).closest( 'tr' ), |
| 400 | + url_resource: $( '#auth_settings_oauth2_url_resource' ).closest( 'tr' ), |
| 401 | + attr_username: $( '#auth_settings_oauth2_attr_username' ).closest( 'tr' ), |
| 402 | + attr_email: $( '#auth_settings_oauth2_attr_email' ).closest( 'tr' ), |
| 403 | + attr_first_name: $( '#auth_settings_oauth2_attr_first_name' ).closest( 'tr' ), |
| 404 | + attr_last_name: $( '#auth_settings_oauth2_attr_last_name' ).closest( 'tr' ), |
| 405 | + attr_update_on_login: $( '#auth_settings_oauth2_attr_update_on_login' ).closest( 'tr' ), |
| 406 | + } ); |
| 407 | + // OAuth2 settings below are for any additional OAuth2 servers configured (up to 20). |
| 408 | + for ( var i = 2; i <= parseInt( $( '#auth_settings_oauth2_num_servers' ).val() ) && i <= 20; i++ ) { |
| 409 | + auth_settings_external_oauth2_servers.push( { |
| 410 | + provider: $( '#auth_settings_oauth2_provider_' + i ).closest( 'tr' ), |
| 411 | + custom_label: $( '#auth_settings_oauth2_custom_label_' + i ).closest( 'tr' ), |
| 412 | + clientid: $( '#auth_settings_oauth2_clientid_' + i ).closest( 'tr' ), |
| 413 | + clientsecret: $( '#auth_settings_oauth2_clientsecret_' + i ).closest( 'tr' ), |
| 414 | + hosteddomain: $( '#auth_settings_oauth2_hosteddomain_' + i ).closest( 'tr' ), |
| 415 | + tenant_id: $( '#auth_settings_oauth2_tenant_id_' + i ).closest( 'tr' ), |
| 416 | + url_authorize: $( '#auth_settings_oauth2_url_authorize_' + i ).closest( 'tr' ), |
| 417 | + url_token: $( '#auth_settings_oauth2_url_token_' + i ).closest( 'tr' ), |
| 418 | + url_resource: $( '#auth_settings_oauth2_url_resource_' + i ).closest( 'tr' ), |
| 419 | + attr_username: $( '#auth_settings_oauth2_attr_username_' + i ).closest( 'tr' ), |
| 420 | + attr_email: $( '#auth_settings_oauth2_attr_email_' + i ).closest( 'tr' ), |
| 421 | + attr_first_name: $( '#auth_settings_oauth2_attr_first_name_' + i ).closest( 'tr' ), |
| 422 | + attr_last_name: $( '#auth_settings_oauth2_attr_last_name_' + i ).closest( 'tr' ), |
| 423 | + attr_update_on_login: $( '#auth_settings_oauth2_attr_update_on_login_' + i ).closest( 'tr' ), |
| 424 | + } ); |
| 425 | + } |
402 | 426 | var auth_settings_external_google_clientid = $( '#auth_settings_google_clientid' ).closest( 'tr' ); |
403 | 427 | var auth_settings_external_google_clientsecret = $( '#auth_settings_google_clientsecret' ).closest( 'tr' ); |
404 | 428 | var auth_settings_external_google_hosteddomain = $( '#auth_settings_google_hosteddomain' ).closest( 'tr' ); |
|
475 | 499 | animateOption( 'hide_immediately', auth_settings_access_redirect_to_message ); |
476 | 500 | } |
477 | 501 |
|
478 | | - // Hide OAuth2 options if unchecked. |
| 502 | + // Hide OAuth2 options if OAuth2 provider is unchecked. |
479 | 503 | if ( ! $( '#auth_settings_oauth2' ).is( ':checked' ) ) { |
480 | | - animateOption( 'hide_immediately', auth_settings_external_oauth2_provider ); |
481 | | - animateOption( 'hide_immediately', auth_settings_external_oauth2_custom_label ); |
482 | | - animateOption( 'hide_immediately', auth_settings_external_oauth2_clientid ); |
483 | | - animateOption( 'hide_immediately', auth_settings_external_oauth2_clientsecret ); |
484 | | - animateOption( 'hide_immediately', auth_settings_external_oauth2_hosteddomain ); |
485 | 504 | animateOption( 'hide_immediately', auth_settings_external_oauth2_auto_login ); |
| 505 | + animateOption( 'hide_immediately', auth_settings_external_oauth2_num_servers ); |
486 | 506 | } |
487 | | - |
488 | | - // Hide OAuth2 generic options if generic isn't chosen. |
489 | | - if ( ! $( '#auth_settings_oauth2' ).is( ':checked' ) || 'generic' !== $( '#auth_settings_oauth2_provider' ).val() ) { |
490 | | - animateOption( 'hide_immediately', auth_settings_external_oauth2_url_authorize ); |
491 | | - animateOption( 'hide_immediately', auth_settings_external_oauth2_url_token ); |
492 | | - animateOption( 'hide_immediately', auth_settings_external_oauth2_url_resource ); |
493 | | - animateOption( 'hide_immediately', auth_settings_external_oauth2_attr_username ); |
494 | | - animateOption( 'hide_immediately', auth_settings_external_oauth2_attr_email ); |
495 | | - animateOption( 'hide_immediately', auth_settings_external_oauth2_attr_first_name ); |
496 | | - animateOption( 'hide_immediately', auth_settings_external_oauth2_attr_last_name ); |
497 | | - animateOption( 'hide_immediately', auth_settings_external_oauth2_attr_update_on_login ); |
498 | | - } |
499 | | - |
500 | | - // Hide OAuth2 Tenant ID if azure isn't chosen. |
501 | | - if ( ! $( '#auth_settings_oauth2' ).is( ':checked' ) || 'azure' !== $( '#auth_settings_oauth2_provider' ).val() ) { |
502 | | - animateOption( 'hide_immediately', auth_settings_external_oauth2_tenant_id ); |
503 | | - } |
| 507 | + auth_settings_external_oauth2_servers.forEach( function( server ) { |
| 508 | + // Hide OAuth2 options if OAuth2 provider is unchecked. |
| 509 | + if ( ! $( '#auth_settings_oauth2' ).is( ':checked' ) ) { |
| 510 | + animateOption( 'hide_immediately', server.provider ); |
| 511 | + animateOption( 'hide_immediately', server.custom_label ); |
| 512 | + animateOption( 'hide_immediately', server.clientid ); |
| 513 | + animateOption( 'hide_immediately', server.clientsecret ); |
| 514 | + animateOption( 'hide_immediately', server.hosteddomain ); |
| 515 | + } |
| 516 | + // Hide OAuth2 generic options if OAuth2 provider is unchecked or generic isn't chosen. |
| 517 | + if ( ! $( '#auth_settings_oauth2' ).is( ':checked' ) || 'generic' !== server.provider.find( 'select' ).val() ) { |
| 518 | + animateOption( 'hide_immediately', server.url_authorize ); |
| 519 | + animateOption( 'hide_immediately', server.url_token ); |
| 520 | + animateOption( 'hide_immediately', server.url_resource ); |
| 521 | + animateOption( 'hide_immediately', server.attr_username ); |
| 522 | + animateOption( 'hide_immediately', server.attr_email ); |
| 523 | + animateOption( 'hide_immediately', server.attr_first_name ); |
| 524 | + animateOption( 'hide_immediately', server.attr_last_name ); |
| 525 | + animateOption( 'hide_immediately', server.attr_update_on_login ); |
| 526 | + } |
| 527 | + // Hide OAuth2 Tenant ID if OAuth2 provider is unchecked or azure isn't chosen. |
| 528 | + if ( ! $( '#auth_settings_oauth2' ).is( ':checked' ) || 'azure' !== server.provider.find( 'select' ).val() ) { |
| 529 | + animateOption( 'hide_immediately', server.tenant_id ); |
| 530 | + } |
| 531 | + } ); |
504 | 532 |
|
505 | 533 | // Hide Google options if unchecked |
506 | 534 | if ( ! $( '#auth_settings_google' ).is( ':checked' ) ) { |
|
584 | 612 | // Event handler: Show/hide OAuth2 options based on checkbox. |
585 | 613 | $( 'input[name="auth_settings[oauth2]"]' ).on( 'change', function() { |
586 | 614 | var action = $( this ).is( ':checked' ) ? 'show' : 'hide'; |
587 | | - animateOption( action, auth_settings_external_oauth2_provider ); |
588 | | - animateOption( action, auth_settings_external_oauth2_custom_label ); |
589 | | - animateOption( action, auth_settings_external_oauth2_clientid ); |
590 | | - animateOption( action, auth_settings_external_oauth2_clientsecret ); |
591 | | - animateOption( action, auth_settings_external_oauth2_hosteddomain ); |
592 | 615 | animateOption( action, auth_settings_external_oauth2_auto_login ); |
| 616 | + animateOption( action, auth_settings_external_oauth2_num_servers ); |
| 617 | + auth_settings_external_oauth2_servers.forEach( function( server ) { |
| 618 | + animateOption( action, server.provider ); |
| 619 | + animateOption( action, server.custom_label ); |
| 620 | + animateOption( action, server.clientid ); |
| 621 | + animateOption( action, server.clientsecret ); |
| 622 | + animateOption( action, server.hosteddomain ); |
| 623 | + }); |
593 | 624 | }); |
594 | 625 |
|
595 | | - // Event handler: Show/hide OAuth2 generic options based on provider. |
596 | | - $( 'select[name="auth_settings[oauth2_provider]"]' ).on( 'change', function() { |
597 | | - var action = 'generic' === $( this ).val() ? 'show' : 'hide'; |
598 | | - animateOption( action, auth_settings_external_oauth2_url_authorize ); |
599 | | - animateOption( action, auth_settings_external_oauth2_url_token ); |
600 | | - animateOption( action, auth_settings_external_oauth2_url_resource ); |
601 | | - animateOption( action, auth_settings_external_oauth2_attr_username ); |
602 | | - animateOption( action, auth_settings_external_oauth2_attr_email ); |
603 | | - animateOption( action, auth_settings_external_oauth2_attr_first_name ); |
604 | | - animateOption( action, auth_settings_external_oauth2_attr_last_name ); |
605 | | - animateOption( action, auth_settings_external_oauth2_attr_update_on_login ); |
606 | | - action = 'azure' === $( this ).val() ? 'show' : 'hide'; |
607 | | - animateOption( action, auth_settings_external_oauth2_tenant_id ); |
| 626 | + // Event handler: Show/hide OAuth2 generic/azure options based on provider. |
| 627 | + auth_settings_external_oauth2_servers.forEach( function( server ) { |
| 628 | + server.provider.find( 'select' ).on( 'change', function() { |
| 629 | + var action = 'generic' === $( this ).val() ? 'show' : 'hide'; |
| 630 | + animateOption( action, server.url_authorize ); |
| 631 | + animateOption( action, server.url_token ); |
| 632 | + animateOption( action, server.url_resource ); |
| 633 | + animateOption( action, server.attr_username ); |
| 634 | + animateOption( action, server.attr_email ); |
| 635 | + animateOption( action, server.attr_first_name ); |
| 636 | + animateOption( action, server.attr_last_name ); |
| 637 | + animateOption( action, server.attr_update_on_login ); |
| 638 | + action = 'azure' === $( this ).val() ? 'show' : 'hide'; |
| 639 | + animateOption( action, server.tenant_id ); |
| 640 | + }); |
608 | 641 | }); |
609 | 642 |
|
610 | 643 | // Event handler: Show/hide Google options based on checkbox |
|
1191 | 1224 | params.access_default_role = $( '#auth_settings_access_default_role' ).val(); |
1192 | 1225 |
|
1193 | 1226 | params.oauth2 = $( '#auth_settings_oauth2' ).is( ':checked' ) ? '1' : ''; |
| 1227 | + params.oauth2_auto_login = $( '#auth_settings_oauth2_auto_login' ).val(); |
| 1228 | + params.oauth2_num_servers = parseInt( $( '#auth_settings_oauth2_num_servers' ).val() ); |
1194 | 1229 | params.oauth2_provider = $( '#auth_settings_oauth2_provider' ).val(); |
1195 | 1230 | params.oauth2_custom_label = $( '#auth_settings_oauth2_custom_label' ).val(); |
1196 | 1231 | params.oauth2_clientid = $( '#auth_settings_oauth2_clientid' ).val(); |
|
1205 | 1240 | params.oauth2_attr_first_name = $( '#auth_settings_oauth2_attr_first_name' ).val(); |
1206 | 1241 | params.oauth2_attr_last_name = $( '#auth_settings_oauth2_attr_last_name' ).val(); |
1207 | 1242 | params.oauth2_attr_update_on_login = $( '#auth_settings_oauth2_attr_update_on_login' ).val(); |
1208 | | - params.oauth2_auto_login = $( '#auth_settings_oauth2_auto_login' ).is( ':checked' ) ? '1' : ''; |
| 1243 | + if ( params.oauth2_num_servers > 1 ) { |
| 1244 | + for ( var oauth2_num_server = 2; oauth2_num_server <= params.oauth2_num_servers && oauth2_num_server <= 20; oauth2_num_server++ ) { |
| 1245 | + params['oauth2_provider_' + oauth2_num_server] = $( '#auth_settings_oauth2_provider_' + oauth2_num_server ).val(); |
| 1246 | + params['oauth2_custom_label_' + oauth2_num_server] = $( '#auth_settings_oauth2_custom_label_' + oauth2_num_server ).val(); |
| 1247 | + params['oauth2_clientid_' + oauth2_num_server] = $( '#auth_settings_oauth2_clientid_' + oauth2_num_server ).val(); |
| 1248 | + params['oauth2_clientsecret_' + oauth2_num_server] = $( '#auth_settings_oauth2_clientsecret_' + oauth2_num_server ).val(); |
| 1249 | + params['oauth2_hosteddomain_' + oauth2_num_server] = $( '#auth_settings_oauth2_hosteddomain_' + oauth2_num_server ).val(); |
| 1250 | + params['oauth2_tenant_id_' + oauth2_num_server] = $( '#auth_settings_oauth2_tenant_id_' + oauth2_num_server ).val(); |
| 1251 | + params['oauth2_url_authorize_' + oauth2_num_server] = $( '#auth_settings_oauth2_url_authorize_' + oauth2_num_server ).val(); |
| 1252 | + params['oauth2_url_token_' + oauth2_num_server] = $( '#auth_settings_oauth2_url_token_' + oauth2_num_server ).val(); |
| 1253 | + params['oauth2_url_resource_' + oauth2_num_server] = $( '#auth_settings_oauth2_url_resource_' + oauth2_num_server ).val(); |
| 1254 | + params['oauth2_attr_username_' + oauth2_num_server] = $( '#auth_settings_oauth2_attr_username_' + oauth2_num_server ).val(); |
| 1255 | + params['oauth2_attr_email_' + oauth2_num_server] = $( '#auth_settings_oauth2_attr_email_' + oauth2_num_server ).val(); |
| 1256 | + params['oauth2_attr_first_name_' + oauth2_num_server] = $( '#auth_settings_oauth2_attr_first_name_' + oauth2_num_server ).val(); |
| 1257 | + params['oauth2_attr_last_name_' + oauth2_num_server] = $( '#auth_settings_oauth2_attr_last_name_' + oauth2_num_server ).val(); |
| 1258 | + params['oauth2_attr_update_on_login_' + oauth2_num_server] = $( '#auth_settings_oauth2_attr_update_on_login_' + oauth2_num_server ).val(); |
| 1259 | + } |
| 1260 | + } |
1209 | 1261 |
|
1210 | 1262 | params.google = $( '#auth_settings_google' ).is( ':checked' ) ? '1' : ''; |
1211 | 1263 | params.google_clientid = $( '#auth_settings_google_clientid' ).val(); |
|
1285 | 1337 | // Disable wait cursor. |
1286 | 1338 | $( 'html' ).removeClass( 'busy' ); |
1287 | 1339 |
|
1288 | | - // If the save was successful, and we have more than 1 CAS servers configured, |
1289 | | - // reload the page to render the additional CAS server settings fields. |
1290 | | - if ( succeeded && params.cas_num_servers > 1 ) { |
| 1340 | + // If the save was successful, and we have more than 1 CAS or OAuth2 |
| 1341 | + // servers configured, reload the page to render the additional CAS/Oauth2 |
| 1342 | + // server settings fields. |
| 1343 | + if ( succeeded && ( params.cas_num_servers > 1 || params.oauth2_num_servers > 1 ) ) { |
1291 | 1344 | location.reload(); |
1292 | 1345 | } |
1293 | 1346 | }).fail( function() { |
|
0 commit comments