Пример #1
0
 /**
  * 
  * 
  */
 protected function updateCredentials($response, $callback)
 {
     $session = $response->originRequest()->session();
     $url = $this->server->get('api_url') . $this->server['config']->get('grant_path');
     $data = json_encode(array('client_id' => $this->server['config']->get('client_id'), 'client_secret' => $this->server['config']->get('client_secret'), 'refresh_token' => $session->get('oauth_grant.refresh_token'), 'grant_type' => 'refresh_token'));
     $request = $this->client->request('POST', $url, array('content-type' => 'application/json;charset=UTF-8', 'content-length' => strlen($data)));
     $request->on('response', function ($clientResponse) use($response, $request, $callback, $session) {
         if ($clientResponse->getCode() != 200) {
             $clientResponse->on('data', function ($data) use($clientResponse, $request, $callback, $session) {
                 $session->forget('oauth_grant');
                 $this->server->log('Não foi possível autenticar o usuário utilizando o refresh token (%s).', [$data]);
             });
             return $callback($clientResponse);
         }
         $clientResponse->on('data', function ($data) {
             $this->bufferData($data);
         });
         $clientResponse->on('end', function ($data) use($clientResponse, $response, $callback) {
             $data = $this->getDataEnd();
             $this->processResponse($response, json_decode($data, true));
             $callback($clientResponse);
         });
     });
     $request->end($data);
 }
Пример #2
0
 /**
  * Ends request and dispatch
  * 
  * @return void
  */
 public function dispatch()
 {
     $method = $this->original->getMethod();
     $url = $this->server->get('api_url') . $this->getPath();
     $headers = Arr::except($this->headers()->all(), ['cookie']);
     $this->request = $this->createClientRequest($method, $url, $headers);
     $this->request->end($this->getBufferEnd());
 }