Example #1
0
File: accounts.php Project: n8b/VMN
<?php

elgg_load_css('hybridauth.css');
$user = elgg_get_page_owner_entity();
$ha_session = new \Elgg\HybridAuth\Session($user);
$providers = $ha_session->getProviders();
foreach ($providers as $ha_provider) {
    if (!$ha_provider->isEnabled()) {
        continue;
    }
    $provider = $ha_provider->getName();
    $openid = $ha_provider->getOpenId();
    $icon_classes = array(strtolower("auth-{$provider}"));
    if ($openid) {
        $icon_classes[] = "auth-openid";
    }
    $title = elgg_view_image_block(elgg_view_icon(implode(' ', $icon_classes)), $provider);
    if ($ha_session->isAuthenticated($ha_provider)) {
        $deauth_url = elgg_http_add_url_query_elements("action/hybridauth/deauthorize", array('provider' => $provider, 'guid' => $user->guid));
        $mod = '<p class="hybridauth-diagnostics-success">' . elgg_echo('hybridauth:provider:user:authenticated') . '</p>';
        $mod .= elgg_view('output/url', array('href' => $deauth_url, 'is_action' => true, 'text' => elgg_echo('hybridauth:provider:user:deauthorize'), 'class' => 'elgg-button elgg-button-action'));
        $mod .= elgg_view("hybridauth/accounts/{$provider}");
    } else {
        $auth_url = elgg_http_add_url_query_elements('hybridauth/authenticate', array('provider' => $provider, 'elgg_forward_url' => urlencode(elgg_normalize_url("hybridauth/accounts/{$user->username}"))));
        $mod = elgg_view('output/url', array('href' => $auth_url, 'text' => elgg_echo('hybridauth:provider:user:authenticate'), 'class' => 'elgg-button elgg-button-action'));
    }
    echo elgg_view_module('info', $title, $mod);
}
<?php

if (!elgg_get_plugin_setting('public_auth', 'elgg_hybridauth')) {
    gatekeeper();
}
$session_owner_guid = get_input('session_owner_guid');
$session_owner = get_entity($session_owner_guid);
$session_name = get_input('session_name');
$session_handle = get_input('session_handle');
$user = $session_owner ?: elgg_get_logged_in_user_entity();
$ha_session = new Elgg\HybridAuth\Session($user, $session_name, $session_handle);
$provider_name = get_input('provider');
$provider = $ha_session->getProvider($provider_name);
if (!$provider) {
    forward(REFERRER, '400');
    // bad request
}
$scope = get_input('scope');
if ($scope) {
    $uid = (int) $ha_session->isAuthenticated($provider);
    if (empty($_SESSION["HA:{$provider_name}:last_scope:{$uid}"])) {
        $_SESSION["HA:{$provider_name}:last_scope:{$uid}"] = 'default';
    }
    if ($_SESSION["HA:{$provider_name}:last_scope:{$uid}"] != $scope) {
        // 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);
Example #3
0
<?php

$provider = get_input('provider');
$guid = get_input('guid');
$user = get_entity($guid);
if (!$provider || !$user) {
    forward('', '404');
}
$session_name = get_input('session_name');
$session_handle = get_input('session_handle');
$ha_session = new Elgg\HybridAuth\Session($user, $session_name, $session_handle);
$ha_provider = $ha_session->getProvider($provider);
if (!$ha_provider) {
    forward('', '404');
}
if ($ha_session->deauthenticate($ha_provider)) {
    system_message(elgg_echo('hybridauth:provider:user:deauthorized'));
} else {
    register_error(elgg_echo('hybridauth:provider:user:deauthorized:error'));
}
forward(REFERER);
Example #4
0
<?php

$username = elgg_extract('username', $vars);
$users = get_user_by_email($username);
if (empty($users)) {
    return;
}
$user = $users[0];
$aux_provider = elgg_extract('provider', $vars);
$aux_provider_uid = elgg_extract('provider_uid', $vars);
$active = array();
$ha_session = new \Elgg\HybridAuth\Session($user);
$providers = $ha_session->getEnabledProviders();
foreach ($providers as $provider) {
    if ($ha_session->isAuthenticated($provider)) {
        $active[] = $provider->getName();
    }
}
if (empty($active)) {
    return;
}
elgg_load_css('hybridauth.css');
echo '<div class="hybridauth-form">';
echo '<label class="hybridauth-form-label">' . elgg_echo('hybridauth:connect') . '</label>';
echo '<ul class="hybridauth-form-icons">';
foreach ($active as $provider) {
    echo '<li>';
    echo elgg_view('output/url', array('text' => elgg_view_icon(strtolower("auth-{$provider}-large")), 'href' => "hybridauth/authenticate?provider={$provider}&aux_provider={$aux_provider}&aux_provider_uid={$aux_provider_uid}", 'title' => $provider, 'class' => 'hybridauth-start-authentication'));
    echo '</li>';
}
echo '</ul>';
Example #5
0
File: start.php Project: 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;
}
Example #6
0
File: login.php Project: n8b/VMN
<?php

if (!elgg_get_plugin_setting('public_auth', 'elgg_hybridauth')) {
    return;
}
$ha_session = new \Elgg\HybridAuth\Session($user);
$providers = $ha_session->getEnabledProviders();
if (empty($providers)) {
    return;
}
elgg_load_css('hybridauth.css');
echo '<div class="hybridauth-form">';
echo '<label class="hybridauth-form-label">' . elgg_echo('hybridauth:connect') . '</label>';
echo '<ul class="hybridauth-form-icons">';
foreach ($providers as $provider) {
    $name = $provider->getName();
    echo '<li>';
    echo elgg_view('output/url', array('text' => elgg_view_icon(strtolower("auth-{$name}-large")), 'href' => "hybridauth/authenticate?provider={$name}", 'title' => $name, 'class' => 'hybridauth-start-authentication'));
    echo '</li>';
}
echo '</ul>';
echo '</div>';