示例#1
0
 /**
  * pretty much a helper function to set up the request
  */
 public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters = NULL)
 {
     $parameters = $parameters ? $parameters : array();
     $defaults = array("oauth_version" => Request::$version, "oauth_nonce" => Request::generate_nonce(), "oauth_timestamp" => Request::generate_timestamp(), "oauth_consumer_key" => $consumer->key);
     if ($token) {
         $defaults['oauth_token'] = $token->key;
     }
     $parameters = array_merge($defaults, $parameters);
     return new Request($http_method, $http_url, $parameters);
 }
示例#2
0
 /**
  * Obtains a user's login details from a token key and secret
  * 
  * @param string $tokenKey
  * @param secret $tokenSecret
  * @return object|false
  */
 public function checkLogin($tokenKey, $tokenSecret, $tokenVerifier)
 {
     $this->token = new OAuth\Consumer($tokenKey, $tokenSecret);
     // the location to send a cURL request to to obtain this user's details
     $returnUrl = $this->base . $this->loc_api . $this->loc_return . $this->format . '/';
     // generate a token request call using post data
     $req = OAuth\Request::from_consumer_and_token($this->consumer, $this->token, "POST", $returnUrl, array('oauth_token' => $tokenKey, 'oauth_verifier' => $tokenVerifier));
     // sign the request using the specified signature/encryption method (set in this class)
     $req->sign_request($this->signature, $this->consumer, $this->token);
     // post the details to VATSIM and obtain the result
     $response = $this->curlRequest($returnUrl, $req->to_postdata());
     if ($response) {
         // convert using our response format (depending upon user preference)
         $sso = $this->responseFormat($response);
         // did VATSIM return a successful result?
         if ($sso->request->result == 'success') {
             // one time use of tokens only, token no longer valid
             $this->token = false;
             // return the full object to the user
             return $sso;
         } else {
             // oauth returned a failed request, store the error details
             $this->error = array('type' => 'oauth_response', 'code' => false, 'message' => $sso->request->message);
             return false;
         }
     } else {
         // cURL response failed
         return false;
     }
 }