Skip to content

Commit

Permalink
Merge pull request #66 from humanmade/backport-64-to-v7-branch
Browse files Browse the repository at this point in the history
[Backport v7-branch] Allow SAML SSO URLs to function when require login is enabled
  • Loading branch information
roborourke authored Jul 30, 2021
2 parents a4a604b + d861ba0 commit d990211
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions inc/saml/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function bootstrap() {
add_filter( 'wpsimplesaml_idp_metadata_xml_path', __NAMESPACE__ . '\\get_idp_metadata_file_path' );
add_filter( 'pre_site_option_sso_sp_base', __NAMESPACE__ . '\\get_sp_client_id' );
add_filter( 'pre_site_option_sso_enabled', __NAMESPACE__ . '\\get_sso_enabled_option' );
add_filter( 'hm-require-login.allowed_pages', __NAMESPACE__ . '\\allow_sso_urls', 10, 2 );
require_once Altis\ROOT_DIR . '/vendor/humanmade/wp-simple-saml/plugin.php';

add_action( 'plugins_loaded', __NAMESPACE__ . '\\remove_plugin_admin_ui' );
Expand Down Expand Up @@ -83,3 +84,18 @@ function remove_plugin_admin_ui() {
remove_action( 'wpmu_options', 'HumanMade\\SimpleSaml\\Admin\\network_settings_fields' );
remove_action( 'update_wpmu_options', 'HumanMade\\SimpleSaml\\Admin\\save_network_settings_fields' );
}

/**
* Ensure SAML endpoints are not redirected when require login is active.
*
* @param array $allowed Allowed PHP pages.
* @param string|null $page The current page.
* @return array
*/
function allow_sso_urls( array $allowed, ?string $page ) : array {
if ( $page === 'index.php' && strpos( $_SERVER['REQUEST_URI'], '/sso/' ) !== false ) {
$allowed[] = $page;
}

return $allowed;
}

0 comments on commit d990211

Please sign in to comment.