<?php // failsafe to allow direct calls to the template if (is_null($sso_objects) || is_null($action)) { die; } $site_args = array('action' => $action); $network_sites = array_diff(WP_MultiSite_SSO::get_network_sites(), array(esc_url(home_url()))); // add the site args to each site $sso_sites = array(); foreach ($network_sites as $blog_id => $blog_url) { $blog_args = $site_args; if (isset($sso_objects[$blog_id])) { $blog_args['sso'] = urlencode($sso_objects[$blog_id]); } $sso_sites[] = esc_url_raw(add_query_arg($blog_args, $blog_url)); } $body_text = __('Please wait...', 'wp-multisite-sso'); if (WP_MultiSite_SSO::LOGIN_ACTION === $action) { $body_text = sprintf(__('Logging in to network sites. %s', 'wp-multisite-sso'), $body_text); } else { $body_text = sprintf(__('Logging out of network sites. %s', 'wp-multisite-sso'), $body_text); } $sso_options = get_option(WP_MultiSite_SSO::SETTINGS_SLUG); $load_wp_css = isset($sso_options['load_wp_css']) ? intval($sso_options['load_wp_css']) : 1; $load_custom_css = isset($sso_options['load_custom_css']) ? intval($sso_options['load_custom_css']) : 1; $custom_css = isset($sso_options['loginout_css']) ? $sso_options['loginout_css'] : ''; $body_classes = array('sso-body', 'login', 'login-action-login', 'wp-core-ui', 'locale-' . sanitize_html_class(strtolower(str_replace('_', '-', get_locale())))); $body_classes = apply_filters('sso_login_logout_body_class', $body_classes, $action); $login_header_url = network_home_url(); $login_header_title = get_current_site()->site_name;
/** * Provides the functionality to sign the user in to the network sites once * they have signed in to the current blog. * @global type $current_site * @param type $username * @param type $user */ public static function handle_login($username, $user) { global $current_site; // setup variables $time = time(); $user_hash = md5(sprintf(self::$user_hash_md5_format, $user->ID)); $network_sites = array_diff(WP_MultiSite_SSO::get_network_sites(), array(esc_url(home_url()))); $current_blog_id = get_current_blog_id(); // IP address. $ip_address = ''; if (!empty($_SERVER['REMOTE_ADDR'])) { $ip_address = $_SERVER['REMOTE_ADDR']; } // User-agent. $user_agent = ''; if (!empty($_SERVER['HTTP_USER_AGENT'])) { $user_agent = wp_unslash($_SERVER['HTTP_USER_AGENT']); } foreach (array_keys($network_sites) as $blog_id) { // build the sso objects to send $sso_objects[$blog_id] = array('user_hash' => $user_hash, 'user_id' => $user->ID, 'src_blog_id' => $current_blog_id, 'dest_blog_id' => $blog_id, 'timestamp' => $time, 'ip_address' => $ip_address, 'user_agent' => $user_agent); } // encrypt the sso object $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB), MCRYPT_RAND); $sso_objects = array_map(function ($sso_object) use($iv) { // encode the sso object $sso_object = json_encode($sso_object); return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, substr(AUTH_SALT, 0, 32), $sso_object, MCRYPT_MODE_ECB, $iv)); }, $sso_objects); // add reference to hash to the user's meta, store the time and all sso objects $user_meta = array('hash' => $user_hash, 'value' => array('timestamp' => $time, 'keys' => $sso_objects)); update_user_meta($user->ID, self::USER_META_KEY, $user_meta); $action = self::LOGIN_ACTION; include __DIR__ . '/inc/sso.php'; die; }