Exemple #1
0
 /**
  * Parse an access token response and assign
  * credential values.
  *
  * @param Vinelab\Http\Response $response
  *
  * @return Vinelab\Auth\Social\Providers\Twitter\OAuthToken
  */
 public function makeAccessToken(Response $response)
 {
     parse_str($response->content(), $params);
     $this->validateAccessTokenResponse($params);
     $this->credentials['key'] = $params['oauth_token'];
     $this->credentials['secret'] = $params['oauth_token_secret'];
     $this->credentials['user_id'] = $params['user_id'];
     $this->credentials['screen_name'] = $params['screen_name'];
     return $this;
 }
Exemple #2
0
 /**
  * Parses an access token response.
  *
  * @param Vinelab\Http\Response $response
  *
  * @return array
  */
 public function parseResponse(Response $response)
 {
     $json = $response->json();
     /*
      * The returned response must not be in JSON
      * format, unless it is an error.
      */
     if (!is_null($json)) {
         if (isset($json->error)) {
             $error = $json->error;
             throw new AccessTokenException($error->type . ': ' . $error->message, $error->code);
         }
     }
     $token = $response->content();
     return $this->parseToken($token);
 }
Exemple #3
0
 /**
  * Send a CURL request.
  *
  * @return Vinelab\Http\Response
  */
 public function send()
 {
     $cURLOptions = array(CURLOPT_HTTP_VERSION => $this->getCurlHttpVersion(), CURLOPT_URL => $this->url, CURLOPT_CUSTOMREQUEST => $this->method, CURLOPT_RETURNTRANSFER => $this->returnTransfer, CURLOPT_HTTPHEADER => $this->headers, CURLOPT_HEADER => true, CURLINFO_HEADER_OUT => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => 50);
     if ($this->method === static::method('POST') || $this->method === static::method('PUT') || $this->method === static::method('PATCH')) {
         if (count($this->params) > 0) {
             $cURLOptions[CURLOPT_POST] = count($this->params);
             $cURLOptions[CURLOPT_POSTFIELDS] = $this->json ? json_encode($this->params) : $this->params;
         } elseif (!is_null($this->content)) {
             $cURLOptions[CURLOPT_POST] = strlen($this->content);
             $cURLOptions[CURLOPT_POSTFIELDS] = $this->json ? json_encode($this->content) : $this->content;
         }
     } elseif (count($this->params) > 0) {
         $this->url = $this->url . '?' . http_build_query($this->params);
         $cURLOptions[CURLOPT_URL] = $this->url;
     } elseif (!is_null($this->content)) {
         $cURLOptions[CURLOPT_URL] = $this->url . '?' . $this->content;
     }
     // initialize cURL
     $cURL = curl_init();
     curl_setopt_array($cURL, $cURLOptions);
     return Response::make($cURL);
 }
Exemple #4
0
 /**
  * Parses a response coming from Facebook
  * containing a profile.
  *
  * @param Vinelab\Http\Response                  $response
  * @param Vinelab\Contracts\AccessTokenInterface $access_token
  *
  * @return Vinelab\Auth\Social\Profile
  */
 public function parseProfileResponse(Response $response, AccessTokenInterface $access_token)
 {
     $profile = $response->json();
     if (gettype($profile) !== 'object') {
         throw new InvalidProfileException();
     }
     if (isset($profile->error)) {
         $error = $profile->error;
         throw new InvalidProfileException($error->type . ': ' . $error->message, $error->code);
     }
     $profile->access_token = $access_token->token();
     return $this->profile->instantiate($profile, $this->name);
 }
Exemple #5
0
 /**
  * Send a CURL request.
  *
  * @return Vinelab\Http\Response
  */
 public function send()
 {
     $cURLOptions = array(CURLOPT_HTTP_VERSION => $this->getCurlHttpVersion(), CURLOPT_URL => $this->url, CURLOPT_CUSTOMREQUEST => $this->method, CURLOPT_HTTPHEADER => $this->headers, CURLOPT_HEADER => true, CURLINFO_HEADER_OUT => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => $this->maxRedirects, CURLOPT_TIMEOUT => $this->timeout);
     //digest auth support
     if (count($this->digestAuth) > 0) {
         $cURLOptions[CURLOPT_HTTPAUTH] = CURLAUTH_DIGEST;
         $cURLOptions[CURLOPT_USERPWD] = $this->digestAuth['username'] . ":" . $this->digestAuth['password'];
     } else {
         if (count($this->basicAuth) > 0) {
             $cURLOptions[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC;
             $cURLOptions[CURLOPT_USERPWD] = $this->basicAuth['username'] . ":" . $this->basicAuth['password'];
         }
     }
     if ($this->method === static::method('POST') || $this->method === static::method('PUT') || $this->method === static::method('PATCH')) {
         if (count($this->params) > 0) {
             $cURLOptions[CURLOPT_POST] = count($this->params);
             $cURLOptions[CURLOPT_POSTFIELDS] = $this->json ? json_encode($this->params) : $this->params;
         } elseif (!is_null($this->content)) {
             $cURLOptions[CURLOPT_POST] = strlen($this->content);
             $cURLOptions[CURLOPT_POSTFIELDS] = $this->json ? json_encode($this->content) : $this->content;
         }
     } elseif (count($this->params) > 0) {
         $this->url = $this->url . '?' . http_build_query($this->params);
         $cURLOptions[CURLOPT_URL] = $this->url;
     } elseif (!is_null($this->content)) {
         $cURLOptions[CURLOPT_URL] = $this->url . '?' . $this->content;
     }
     // initialize cURL
     $cURL = curl_init();
     curl_setopt_array($cURL, $cURLOptions);
     return Response::make($cURL);
 }