public getRequestToken ( $requestTokenURL, $callback = 'oob', $httpMethod = 'POST', array $parameters = [] ) | ||
$requestTokenURL | ||
$callback | An absolute URL to which the server will redirect the resource owner back when the Resource Owner Authorization step is completed. If the client is unable to receive callbacks or a callback URL has been established via other means, the parameter value MUST be set to oob (case sensitive), to indicate an out-of-band configuration. Section 2.1 from http://tools.ietf.org/html/rfc5849 | |
$httpMethod | 'POST' or 'GET' | |
$parameters | array |
/** * ask tumblr for an access-key * * @author Matthias Pfefferle * @return OAuthToken */ public function getRequestToken() { $lRequestToken = OAuthClient::getRequestToken($this->getConsumer(), "http://www.tumblr.com/oauth/request_token", 'GET', array("oauth_callback" => $this->getCallbackUri())); // save the request token OauthRequestTokenTable::saveToken($lRequestToken, $this->getCommunity()); return $lRequestToken; }
/** * checks if an authentication is needed and than redirects to the * corresponding site * * @param string $pUrl * @param ApiClient $pApiClient * @return string */ public static function createRedirectionUrl($pUrl, $pApiClient) { // get user $lUser = sfContext::getInstance()->getUser()->getUser(); // check if there is already an access token $lAccessToken = OAuthServiceTokenPeer::getAccessToken($lUser->getId(), $pApiClient->getId()); if ($lAccessToken) { // if yes, redirect to the normal url $lAuthUrl = $pUrl; } else { // else get request-token $lServiceRegistry = $pApiClient->getOAuthServiceRegistry(); $lOAuthConsumer = new OAuthConsumer($lServiceRegistry->getConsumerKey(), $lServiceRegistry->getConsumerSecret(), null); try { $lRequestToken = OAuthClient::getRequestToken($lOAuthConsumer, $lServiceRegistry->getRequestUri(), 'GET', $lServiceRegistry->getScope(), self::getSignature($lServiceRegistry->getSignatureMethods())); } catch (Exception $e) { throw new OAuthException('wrong consumer settings'); } OAuthServiceTokenPeer::saveRequestToken($lRequestToken, $lUser->getId(), $lServiceRegistry->getId()); $lAuthUrl = $lServiceRegistry->getAuthorizeUri() . "?oauth_token=" . $lRequestToken->key . "&oauth_callback=" . urlencode($pUrl); } return $lAuthUrl; }
/** * Gets a request token from Twitter * * @return OAuthToken $token the request token */ function getRequestToken() { return parent::getRequestToken(self::$requestTokenURL, common_local_url('twitterauthorization')); }
/** * ask twitter for an access-key * * @author Matthias Pfefferle * @return OAuthToken */ public function getRequestToken() { $lRequestToken = OAuthClient::getRequestToken($this->getConsumer(), "http://api.yigg.local/oauth/1/request", 'GET', array("oauth_callback" => $this->getCallbackUri())); sfContext::getInstance()->getLogger()->debug(print_r($lRequestToken, true)); // save the request token OauthRequestTokenTable::saveToken($lRequestToken, $this->getCommunity()); return $lRequestToken; }
} /* Do we have an access token? if not, we need to get one */ if (!isset($_SESSION['access_token'])) { /* Construct api */ $api = new OAuthClient(new EccServiceProvider(), $consumer); /* Two possible conditions: either we're returning from the authorize request or not */ /* Callback from authorize? */ if (!(isset($_SESSION['request_token']) && isset($_GET['oauth_verifier']))) { /* No, we have no access token, we need to get one by generating a request token then asking the user to authorize it */ /* Get request token */ $request_token = $api->getRequestToken($ECC_ACCESS, $APP_CALLBACK_URL); #print_r($request_token); # Useful if you're not sure you've got one $_SESSION['request_token'] = serialize($request_token); /* Redirect user to authorize URL (in this case, it'll be somewhere on entrecredits.com) */ header("Location: " . $api->getAuthorizeUrl($request_token)); die; } else { /* Yep, callback, so we're authorized and we can trade our request token for an access token */ $request_token = unserialize($_SESSION['request_token']); $access_token = $api->getAccessToken($request_token, $_GET['oauth_verifier']); /* Put access token into session. It's all we need now */ $_SESSION['access_token'] = serialize($access_token);