Last active
November 13, 2025 01:04
-
-
Save grand-lotus-iroh/b8e00a3b0beacf6319eacefd5be3f4fa to your computer and use it in GitHub Desktop.
MiniOrange SSO (SAML 2.0 Option 6) – Auto-Redirect from WordPress Login (Server-Side, No Flicker)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * MiniOrange SSO Auto-Redirect for WordPress (SAML 2.0 Option 6) | |
| * | |
| * Effortlessly redirect users from the default WordPress login page (wp-login.php) | |
| * to your miniOrange SAML 2.0 Single Sign-On (SSO) provider. | |
| * | |
| * Features: | |
| * - Automatic server-side redirect using wp_redirect() on the init hook | |
| * - Zero flicker: users never see the WordPress login page | |
| * - Preserves 'redirect_to' parameter for smooth post-login navigation | |
| * - Only redirects users who are not logged in | |
| * - Blocks local WordPress login attempts for enhanced security | |
| * | |
| * This snippet provides a seamless WordPress SSO experience with miniOrange, | |
| * implementing Option 6 Auto-Redirection for SAML 2.0. | |
| * | |
| * Keywords: MiniOrange SSO, WordPress login redirect, wp-login.php auto redirect, | |
| * SAML 2.0 Option 6, WordPress SAML SSO, WordPress Single Sign-On | |
| */ | |
| // Auto-redirect to SSO from wp-login.php (Server-side, no flicker) | |
| function auto_redirect_to_sso_server_side() { | |
| // Only run on wp-login.php, not during SSO callback or other actions | |
| if ( $GLOBALS['pagenow'] === 'wp-login.php' && | |
| empty($_GET['action']) && | |
| empty($_POST['option']) && | |
| empty($_POST['log']) && | |
| !is_user_logged_in() ) { | |
| // Get the base URL | |
| $sp_base_url = site_url(); | |
| // Build the SSO URL | |
| $sso_url = $sp_base_url . '/?option=saml_user_login'; | |
| // If there's a redirect_to parameter, preserve it | |
| if (!empty($_GET['redirect_to'])) { | |
| $sso_url .= '&redirect_to=' . urlencode($_GET['redirect_to']); | |
| } | |
| // Redirect immediately before any output | |
| wp_redirect($sso_url); | |
| exit; | |
| } | |
| } | |
| add_action('init', 'auto_redirect_to_sso_server_side', 1); | |
| // Block local login authentication (keep this for security) | |
| function remove_local_login_authentication($user, $username, $password) { | |
| // Allow SSO authentication to proceed | |
| if (!empty($_POST['option']) && $_POST['option'] === 'saml_user_login') { | |
| return $user; | |
| } | |
| // Block any local login attempts | |
| if (!empty($username) || !empty($password)) { | |
| return new WP_Error('local_login_disabled', 'Local login is disabled. Please use SSO.'); | |
| } | |
| return $user; | |
| } | |
| add_filter('authenticate', 'remove_local_login_authentication', 1, 3); |
Author
grand-lotus-iroh
commented
Nov 13, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment