Exemplo n.º 1
0
 public function access($code, $options = array())
 {
     $params = array('client_id' => $this->client_id, 'client_secret' => $this->client_secret, 'grant_type' => \Arr::get($options, 'grant_type', 'authorization_code'));
     switch ($params['grant_type']) {
         case 'authorization_code':
             $params['code'] = $code;
             $params['redirect_uri'] = \Arr::get($options, 'redirect_uri', $this->redirect_uri);
             break;
         case 'refresh_token':
             $params['refresh_token'] = $code;
             break;
     }
     $response = null;
     $url = $this->url_access_token();
     // Get ready to make a request
     // $request = \Request::forge($url, 'curl');
     //
     // $request->set_params($params);
     switch ($this->method) {
         case 'GET':
             // Need to switch to Request library, but need to test it on one that works
             $url .= '?' . http_build_query($params);
             $response = file_get_contents($url);
             parse_str($response, $return);
             break;
         case 'POST':
             $postdata = http_build_query($params);
             $opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata));
             $context = stream_context_create($opts);
             $response = file_get_contents($url, false, $context);
             $return = get_object_vars(json_decode($response));
             /*
             F**k the request class
             try
             {
             	$request->set_header('Accept', 'application/json');
             	$request->set_method('POST');
             	$request = $request->execute();
             }
             catch (RequestException $e)
             {
             	\Debug::dump($request->response());
             	exit;
             }
             catch (HttpNotFoundException $e)
             {
             	\Debug::dump($request->response());
             	exit;
             }
             			
             $response = $request->response();
             
             logger(\Fuel::L_INFO, 'Access token response: '.print_r($body, true), __METHOD__);
             
             // Try to get the actual response, its hopefully an array
             $body = $response->body();
             */
             break;
         default:
             throw new \OutOfBoundsException("Method '{$this->method}' must be either GET or POST");
     }
     if (isset($return['error'])) {
         throw new Exception($return);
     }
     return Token::forge('access', $return);
 }
Exemplo n.º 2
0
 public function access($code, $options = array())
 {
     $params = array('client_id' => $this->client_id, 'client_secret' => $this->client_secret, 'grant_type' => \Arr::get($options, 'grant_type', 'authorization_code'));
     switch ($params['grant_type']) {
         case 'authorization_code':
             $params['code'] = $code;
             $params['redirect_uri'] = \Arr::get($options, 'redirect_uri', $this->redirect_uri);
             break;
         case 'refresh_token':
             $params['refresh_token'] = $code;
             break;
     }
     $response = null;
     $url = $this->url_access_token();
     // Get ready to make a request
     // $request = \Request::forge($url, 'curl');
     //
     // $request->set_params($params);
     switch ($this->method) {
         case 'GET':
             // Need to switch to Request library, but need to test it on one that works
             $url .= '?' . http_build_query($params);
             $response = file_get_contents($url);
             parse_str($response, $return);
             break;
         case 'POST':
             $postdata = http_build_query($params);
             $opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata));
             $context = stream_context_create($opts);
             $response = file_get_contents($url, false, $context);
             $return = get_object_vars(json_decode($response));
             break;
         default:
             throw new \OutOfBoundsException("Method '{$this->method}' must be either GET or POST");
     }
     if (isset($return['error'])) {
         throw new Exception($return);
     }
     return Token::forge('access', $return);
 }