// Check if scope has been explicitly required
        // Logout the user, and reauthenticate with the requested scope
        $config = $ha_session->getConfig();
        if (!empty($config['providers'][$provider_name])) {
            $config['providers'][$provider_name]['scope'] = urldecode($scope);
        }
        $ha_session->setConfig($config);
        $ha_session->getAdapter($provider)->logout();
        $ha_session->save();
        $_SESSION["HA:{$provider_name}:last_scope:{$uid}"] = $scope;
    } else {
        $_SESSION["HA:{$provider_name}:last_scope:{$uid}"] = 'default';
    }
}
$save_auth = $user ? true : false;
$profile = $ha_session->authenticate($provider, $save_auth);
if (!$profile) {
    echo elgg_view('resources/hybridauth/error', array('provider' => $provider->getName(), 'error' => get_input('error')));
    return;
}
$elgg_forward_url = get_input('elgg_forward_url', $_SESSION['last_forward_from']);
if ($elgg_forward_url) {
    $forward_url = urldecode($elgg_forward_url);
} else {
    $query = parse_url(current_page_url(), PHP_URL_QUERY);
    if ($user) {
        $forward_url = "settings/user/{$user->username}?{$query}";
    } else {
        $forward_url = "?{$query}";
    }
}
示例#2
0
文件: start.php 项目: n8b/VMN
/**
 * Authenticate all providers the user has previously authenticated with
 * This callback is not currently in use. It's added here for illustration purposes
 *
 * @param string   $event "login"
 * @param string   $type  "user"
 * @param ElggUser $user  User entity
 * @return boolean
 */
function elgg_hybridauth_authenticate_all_providers($event, $type, $user)
{
    $ha_session = new \Elgg\HybridAuth\Session($user);
    $providers = $ha_session->getProviders();
    foreach ($providers as $provider) {
        if (!$provider->isEnabled()) {
            continue;
        }
        if (!$ha_session->isAuthenticated($provider) || $ha_session->isConnected($provider)) {
            continue;
        }
        if (!$ha_session->authenticate($provider, false)) {
            register_error(elgg_echo('hybridauth:unlink:provider', array($provider)));
            $ha_session->removeAuthRecord($provider);
        }
    }
    return true;
}