function lookup_token($consumer, $token_type, $token) { $tokEnt = oauth_lookup_token_entity($token, $token_type, $consumer); if ($tokEnt) { return oauth_token_from_entity($tokEnt); } else { return NULL; } }
function oauth_get_new_access_token($consumer, $tokEnt, $url, $verifier = NULL, $parameters = array()) { $reqToken = oauth_token_from_entity($tokEnt); if (!$parameters) { $parameters = oauth_find_parameters($url); } if ($verifier) { // Rev A change: send a registered callback URL with the request $parameters['oauth_verifier'] = $verifier; } $sha = new OAuthSignatureMethod_HMAC_SHA1(); $req = OAuthRequest::from_consumer_and_token($consumer, $reqToken, 'GET', $url, $parameters); $req->sign_request($sha, $consumer, $reqToken); $tokenString = url_getter_getUrl($req->to_url()); $tokenParts = array(); parse_str($tokenString, $tokenParts); $token = new OAuthToken($tokenParts['oauth_token'], $tokenParts['oauth_token_secret']); if ($token->key && $token->secret) { return $token; } else { return NULL; } }
<?php // must be logged in gatekeeper(); global $CONFIG, $SESSION; $verifier = get_input('oauth_verifier', NULL); $return_token_key = get_input('oauth_token', NULL); // get our saved request token $saved_token_guid = $SESSION['oauth_token']; $return_to = $SESSION['oauth_return_to']; $access_url = $SESSION['oauth_access_url']; $tokEnt = get_entity($saved_token_guid); if ($tokEnt && $tokEnt->getOwner() == get_loggedin_user()->getGUID() && (!$return_token_key || $tokEnt->requestToken == $return_token_key)) { $request_token = oauth_token_from_entity($tokEnt); $consumEnt = oauth_lookup_consumer_entity($tokEnt->consumerKey); $consumer = oauth_consumer_from_entity($consumEnt); if ($consumEnt->revA) { $access_token = oauth_get_new_access_token($consumer, $tokEnt, $access_url, $verifier); } else { $access_token = oauth_get_new_access_token($consumer, $tokEnt, $access_url); } if ($access_token) { // save the access token over our existing request token oauth_save_access_token($tokEnt, $access_token); system_message(sprintf(elgg_echo('oauth:success', $consumEnt->name))); } else { // get rid of our bad token and try again $tokEnt->delete(); register_error(sprintf(elgg_echo('oauth:failure', $consumEnt->name))); } } else {