Example #1
0
 /**
  * Pretty much a helper function to set up the request
  *
  * @param \OAuth\Consumer $consumer
  * @param \OAuth\Token $token
  * @param string $httpMethod
  * @param string $httpUrl
  * @param array $parameters OPTIONAL
  * @return \OAuth\Request
  */
 public static function fromConsumerAndToken($consumer, $token, $httpMethod, $httpUrl, $parameters = null)
 {
     $parameters = $parameters ? $parameters : array();
     $defaults = array("oauth_version" => Request::$version, "oauth_nonce" => Request::generateNonce(), "oauth_timestamp" => Request::generateTimestamp(), "oauth_consumer_key" => $consumer->getKey());
     if ($token) {
         $defaults['oauth_token'] = $token->getKey();
     }
     $parameters = array_merge($defaults, $parameters);
     return new Request($httpMethod, $httpUrl, $parameters);
 }
Example #2
0
 public function callback()
 {
     // Create an consumer from the config
     $this->consumer = \OAuth\Consumer::forge($this->config);
     // Load the provider
     $this->provider = \OAuth\Provider::forge($this->provider);
     if ($token = Cookie::get('oauth_token')) {
         // Get the token from storage
         $this->token = unserialize(base64_decode($token));
     }
     if ($this->token and $this->token->access_token !== Input::param('oauth_token')) {
         // Delete the token, it is not valid
         Cookie::delete('oauth_token');
         // Send the user back to the beginning
         exit('invalid token after coming back to site');
     }
     // Get the verifier
     $verifier = Input::param('oauth_verifier');
     // Store the verifier in the token
     $this->token->verifier($verifier);
     // Exchange the request token for an access token
     return $this->provider->access_token($this->consumer, $this->token);
 }