$liveid_appid,"secret"=>$liveid_secret,"securityalgorithm"=>$liveid_secalgo,"returnurl"=>$liveid_return,"policyurl"=>$liveid_policy); if($liveid_appid && $liveid_secret && $liveid_secalgo) { // Initialize the WindowsLiveLogin module. $wll = WindowsLiveLogin::initFromXml(false,$liveid_settings); $wll->setDebug($DEBUG); $APPID = $wll->getAppId(); $login_html = "

This application does not know who you are! Click the Sign in link above.

"; $consent_html = null; // If the user token obtained from sign-in through Web Authentication // has been cached in a site cookie, attempt to process it and extract // the user ID. $token = @$_COOKIE[$WEBAUTHCOOKIE]; $userid = null; if ($token) { $user = $wll->processToken($token); if ($user) { $userid = $user->getId(); } } // If the user ID is obtained successfully, prepare the message // to include the consent URL if a valid token is not present in the // persistent store; otherwise display the contents of the token. if ($userid) { $login_html = "

Now this application knows that you are the user with ID = \"$userid\".

"; $consenturl = $wll->getConsentUrl($OFFERS); $consent_html = "

Please click here to grant consent so that we may access your Windows Live data.

"; // Attempt to get the raw consent token from persistent store for the // current user ID. //$tokens = new TokenDB($TOKENDB); //$token = $tokens->getToken($userid); $token = get_option($userid); $consenttoken = $wll->processConsentToken($token); if ($consenttoken) { if (!$consenttoken->isValid()) { wp_redirect($consenturl); } } // If a consent token is found and is stale, try to refresh it and store // it in persistent storage. if ($consenttoken) { if (!$consenttoken->isValid()) { if ($consenttoken->refresh() && $consenttoken->isValid()) { //$tokens->setToken($userid, $consenttoken->getToken()); update_option($userid,$consenttoken->getToken()); } } if ($consenttoken->isValid()) { // Convert Unix epoch time stamp to user-friendly format. $expiry = $consenttoken->getExpiry(); $expiry = date(DATE_RFC2822, $expiry); //Prepare the message to display the consent token contents. $consent_html = <<Consent token found! The following are its contents..

Delegation token{$consenttoken->getDelegationToken()}
Location ID{$consenttoken->getLocationID()}
Refresh token{$consenttoken->getRefreshToken()}
Expiry{$expiry}
Offers{$consenttoken->getOffersString()}
Context{$consenttoken->getContext()}
Token{$consenttoken->getToken()}
END; } } } // This code embeds the Web Authentication control on your Web page // to display the appropriate application Sign in/Sign out link. $control_html = << END; } if ($consenttoken) { $dt = $consenttoken->getDelegationToken(); $header = array("Authorization: DelegatedToken dt=\"$dt\"\r\n"); $opts = array( 'http'=>array( 'method'=>'GET', 'header'=>$header ) ); $context = stream_context_create($opts); $xml = file_get_contents("https://livecontacts.services.live.com/users/@L@" . $consenttoken->getLocationID() . "/rest/livecontacts", false, $context); if($xml) { $oSimpleXML = new SimpleXMLElement($xml); $contactsArray = array(); $i = 0; $owner = $oSimpleXML->Owner; $liveid = $owner->WindowsLiveID; $email = $owner->Emails->Email->Address; if (trim($email) == "") {$email = $liveid;} $first_name = $owner->Profiles->Personal->FirstName; $last_name = $owner->Profiles->Personal->LastName; $signature = social_connect_generate_signature($liveid); } } ?>