示例#1
0
 function processLogin($query)
 {
     $action = @$query['action'];
     if ($action != 'login') {
         WindowsLiveLogin::debug("Warning: processLogin: query action ignored: {$action}");
         return;
     }
     $token = @$query['stoken'];
     $context = urldecode(@$query['appctx']);
     return WindowsLiveLogin::processToken($token, $context);
 }
function liveid($credentials, $options)
{
    $session =& JFactory::getSession();
    $mainframe =& JFactory::getApplication();
    $db = JFactory::getDBO();
    $db->setQuery('select p.apikey, p.secretkey, p.discovery_url as control_url, p.parameters from #__providers p where p.name=' . $db->Quote($credentials['provider']));
    $consumer = $db->loadObject();
    $appid = $consumer->apikey;
    $secret = $consumer->secret;
    $policyurl = JUri::base() . '/policy.html';
    $returnurl = JUri::base() . '/index.php';
    $wll = new WindowsLiveLogin($appid, $secret, 'wsignin1.0', null, $policyurl, $returnurl);
    $info = array();
    $token = @$_COOKIE['webauthtoken'];
    $info[EXTERNAL_ID] = null;
    $info[STATUS] = Auth_FAILURE;
    if ($token) {
        $user = $wll->processToken($token);
        if ($user) {
            $info[EXTERNAL_ID] = $user->getId();
            $info[STATUS] = Auth_SUCCESS;
        }
    } else {
        $hasbegun = $session->get('liveidhasbegun');
        if (isset($hasbegun) || $hasbegun == 'false') {
            $session->set('liveidhasbegun', 'true');
            $url = $consumer->control_url . '?appid=' . $appid . '&' . $consumer->parameters;
            $mainframe->redirect($url);
        }
        $session->set('liveidhasbegun', 'false');
        $action = $credentials['action'];
        if ($action == '' || $action == 'login') {
            $user = $wll->processLogin($credentials);
            if ($user) {
                if ($user->usePersistentCookie()) {
                    $cookieTtl = time() + 10 * 365 * 24 * 60 * 60;
                    setcookie('webauthtoken', $user->getToken(), $cookieTtl);
                } else {
                    setcookie('webauthtoken', $user->getToken());
                }
                $info[EXTERNAL_ID] = $user->getId();
                $info[STATUS] = Auth_SUCCESS;
            }
            $info[STATUS] = Auth_FAILURE;
        }
    }
    // todo: solicitar email
    $info[EMAIL] = '';
    $info[LABEL] = $info[EMAIL];
    return $info;
}