/**
  * (non-PHPdoc)
  * @see \Socialite\Component\OAuth\SignatureMethod\OAuthSignatureMethod::verify()
  */
 public function verify(OAuthRequest $request, OAuthConsumer $consumer, OAuthToken $token = null, $signature)
 {
     $rawa = OAuth::urldecode($signature);
     $rawb = OAuth::urldecode($this->build($request, $consumer, $token));
     // base64 decode the values
     $decodeda = base64_decode($rawa);
     $decodedb = base64_decode($rawb);
     return rawurlencode($decodeda) == rawurlencode($decodedb);
 }
示例#2
0
 /**
  * Execute the HTTP request.
  *
  * @param  string $data
  */
 public function execute(array $curl_opts = null)
 {
     $curl = curl_init($this->request->getNormalizedUrl());
     curl_setopt($curl, CURLOPT_USERAGENT, self::USERAGENT);
     curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 15);
     curl_setopt($curl, CURLOPT_TIMEOUT, 30);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
     curl_setopt($curl, CURLOPT_HEADER, false);
     curl_setopt($curl, CURLINFO_HEADER_OUT, true);
     // prepare request data
     switch ($this->request->getMethod()) {
         case 'POST':
             $parameters = $this->request->getParameters();
             curl_setopt($curl, CURLOPT_POST, count($parameters));
             curl_setopt($curl, CURLOPT_POSTFIELDS, OAuth::buildHttpQuery($parameters));
             break;
         case 'GET':
             curl_setopt($curl, CURLOPT_URL, $this->request->getRequestUrl());
             break;
     }
     // apply any override parameters
     if (is_array($curl_opts)) {
         curl_setopt_array($curl, $curl_opts);
     }
     // execute the request
     $response = curl_exec($curl);
     if ($response === false) {
         throw new OAuthNetworkException('OAuth Request: ' . curl_error($curl));
     }
     // check for errors
     $info = curl_getinfo($curl);
     if ($info['http_code'] !== 200) {
         throw new OAuthException('OAuth Response: ' . $response);
     }
     // finalize the request
     curl_close($curl);
     // store the response
     $this->response = $response;
 }
示例#3
0
 public function testStaticMethods()
 {
     $this->assertEquals($this->encoded, OAuth::urlencode($this->raw));
     $this->assertEquals($this->raw, OAuth::urldecode($this->encoded));
     $this->assertEquals($this->raw, OAuth::buildHttpQuery($this->array));
 }
示例#4
0
 /**
  * Returns the normalized URL.
  *
  * @param  string $url
  * @return string
  */
 public function getNormalizedUrl($url)
 {
     $parameters = array('{REDIRECT_URI}' => $this->callback, '{CLIENT_ID}' => $this->consumer->getKey(), '{SCOPE}' => implode($this->oauth_scope_separator, $this->getScope()), '{STATE}' => md5(microtime(true)));
     foreach ($parameters as $name => $value) {
         $url = str_replace($name, OAuth::urlencode($value), $url);
     }
     return $url;
 }
示例#5
0
 /**
  * Returns the normalized OAuth request parameters.
  *
  * @return string
  */
 public function getNormalizedParameters()
 {
     return OAuth::buildHttpQuery($this->getBaseParameters());
 }