我正在开发一个插件,允许将本地wordpress帐户链接到双因素身份验证服务。
在Chrome和IE中,登录和链接流程可以完美工作,但重定向会导致Firefox中出现白色页面。奇怪的是,没有任何错误,因为所有代码都已执行,页面的简单F5刷新将显示正确的页面。
正如您在下面的代码中所看到的,我只使用了一次wp\\u redirect()来触发身份验证流,这是可行的,不是问题所在。从那以后,Wordpress将处理所有重定向,在Chrome和IE中表现出色,但在Firefox中却失败了
public function myplugin_callback() {
global $wp_query;
if ($wp_query->get(\'code\')) {
$_SESSION[\'code\'] = $wp_query->get(\'code\');
$_SESSION[\'state\'] = $wp_query->get(\'state\');
wp_redirect(site_url(\'wp-login.php\', \'login\'));
echo \'Please wait, logging in.\';
exit;
}
}
public function myplugin_authenticate($user, $username) {
// do the authentication here
if (isset($_SESSION[\'code\'])) {
/* get userdata via OAuth here */
if (isset($userData[\'email\'])) {
$userSearch = get_user_by(\'email\', $userData[\'email\']);
if ($userSearch) { // user exists
$uuid = get_user_meta($userSearch->ID, \'myplugin_uuid\', true);
if ($uuid == $userData[\'uuid\']) { // user is linked
$user = new WP_User($userSearch->ID);
} else { // user is not linked
$_SESSION[\'myplugin-data\'] = serialize($userData);
$user = new WP_Error(\'denied\', __(\'You already have an account with this email on this blog. Please log in to link this account with our service.\'));
remove_action(\'authenticate\', \'wp_authenticate_username_password\', 20);
}
} else { // user does not exist
$user = new WP_Error();
}
}
unset($_SESSION[\'code\']);
} else { // local login
$userSearch = get_user_by(\'login\', $username);
if ($userSearch) {
$uuid = get_user_meta($userSearch->ID, \'myplugin_uuid\', true);
if (!isset($_SESSION[\'myplugin-data\']) && !empty($uuid) && !$this->myPluginHelper()->getlocalAuthAllowed()) {
$user = new WP_Error(\'denied\', __(\'Local login disabled. Please use myPlugin to log in.\'), \'message\');
remove_action(\'authenticate\', \'wp_authenticate_username_password\', 20);
} else {
add_filter(\'login_redirect\', array($this, \'save_myplugin_uuid\'), 10, 3);
}
}
}
return $user;
}
public function save_myplugin_uuid($redirect_to, $request, $user) {
if (isset($_SESSION[\'myplugin-data\']) && is_a($user, \'WP_User\')) {
$userData = unserialize($_SESSION[\'myplugin-data\']);
update_usermeta($user->ID, \'myplugin_uuid\', $userData[\'uuid\']);
unset($_SESSION[\'myplugin-data\']);
}
return $redirect_to;
}
我在谷歌上搜索了很多交易,但都没有用。有人有主意吗?
ThanksJeroen谢谢