Creates an authorized request

@param $type
@param $url
@param $token

@return \GuzzleHttp\Message\Request|\GuzzleHttp\Message\RequestInterface
436849
protected function createRequest($type, $url, $token)
    {
        return $this->client->createRequest($type, $url, $this->getDefaultHeaders($token));
    }
822206
public function getAuthenticatedRequest($method, $url, $token, array $options = [])
	{
		$options['headers']['Accept'] = 'application/vnd.api+json, application/vnd.api+json; net.youthweb.api.version=0.9';
		$options['headers']['Content-Type'] = 'application/vnd.api+json';

		return parent::getAuthenticatedRequest($method, $url, $token, $options);
	}
1295664
public function get($url, $params=array(), $token='', $secret='') {
        return $this->request('GET', $url, $params, $token, $secret);
    }
251416
def _token_request(self, grant_type, **kwargs):
        
        payload = {
            'grant_type': grant_type,
            'client_id': self._client_id,
            'client_secret': self._client_secret
        }

        payload.update(**kwargs)

        return self._realm.client.post(self.get_url('token_endpoint'),
                                       data=payload)
47554
protected function _addTokenToRequest($token, ServerRequest $request)
    {
        $params = $request->getAttribute('params');
        $params['_csrfToken'] = $token;

        return $request->withAttribute('params', $params);
    }
986932
private function createUrl($request, string $type)
  {
    $data = ($type == 'expire') ? $this->canExpire : $this->except;

    foreach($data as $i => $url) {
      if (str_contains($url, '{*}')) {
        $path = explode('/', (substr($request->path(), 0, 1) == '/' ? substr($request->path(), 1) : $request->path()));
        $url = explode('/', (substr($url, 0, 1) == '/' ? substr($url, 1) : $url));

        if (count($path) == count($url)) {
          $current = [];

          foreach($url as $k => $t) {
            if ($t == $path[$k]) {
              $current[] = $t;
            } elseif ($t == '{*}') {
              $current[] = $path[$k];
            }
          }

          $data[$i] = implode('/', $current);
        }
      }
    }

    if ($type == 'expire') {
      $this->canExpire = $data;
    } else {
      $this->except = $data;
    }
  }
347720
public function newAuthorizeRequest($type, $typeId, $authParams = [])
    {
        if ($this->authorizationServer->hasGrantType('authorization_code')) {
            /** @var AuthCodeGrant $authGrant */
            $authGrant = $this->authorizationServer->getGrantType('authorization_code');
            return $authGrant->newAuthorizeRequest($type, $typeId, $authParams);
        }

        return '';
    }
49465
private function apiCall(string $url, string $token): DeviceAddressInformation
    {
        $response = $this->client->request('GET', $url, [
            'headers' => [
                'Authorization' => 'Bearer '.$token,
                'Accept'        => 'application/json',
            ],
        ]);

        /*
         * Api Call response codes:
         * 200 OK                    Successfully got the address associated with this deviceId.
         * 204 No Content            The query did not return any results.
         * 403 Forbidden            The authentication token is invalid or doesn’t have access to the resource.
         * 405 Method Not Allowed    The method is not supported.
         * 429 Too Many Requests    The skill has been throttled due to an excessive number of requests.
         * 500 Internal Error        An unexpected error occurred.
         */
        switch ($response->getStatusCode()) {
            case 200:
                break;
            case 204:
            case 403:
            case 405:
            case 429:
            case 500:
            default:
                throw new DeviceApiCallException(sprintf('Error in api call (status code:"%s")', $response->getStatusCode()));
        }

        return DeviceAddressInformation::fromApiResponse(json_decode($response->getBody()->getContents(), true));
    }
141729
public function set($token, $type)
    {
        if ($type != 'request_token' && $type != 'access_token') {
            throw new \Dropbox\Exception("Expected a type of either 'request_token' or 'access_token', got '$type'");
        } else {
            $token = $this->encrypt($token);
            $_SESSION[$this->namespace][$this->userID][$type] = $token;
        }
    }
521063
protected function sendRequestHeaders($type, $url, &$params)
    {
        if (!is_array($params)) {
            $params = ['resultcb' => $params];
        }
        if (!isset($params['uri']) || !isset($params['host'])) {
            $prepared = Pool::parseUrl($url);
            if (!$prepared) {
                if (isset($params['resultcb'])) {
                    $params['resultcb'](false);
                }
                return;
            }
            list($params['host'], $params['uri']) = $prepared;
        }
        if ($params['uri'] === '') {
            $params['uri'] = '/';
        }
        $this->lastURL = 'http://' . $params['host'] . $params['uri'];
        if (!isset($params['version'])) {
            $params['version'] = '1.1';
        }
        $this->writeln($type . ' ' . $params['uri'] . ' HTTP/' . $params['version']);
        if (isset($params['proxy'])) {
            if (isset($params['proxy']['auth'])) {
                $this->writeln('Proxy-Authorization: basic ' . base64_encode($params['proxy']['auth']['username'] . ':' . $params['proxy']['auth']['password']));
            }
        }
        $this->writeln('Host: ' . $params['host']);
        if ($this->pool->config->expose->value && !isset($params['headers']['User-Agent'])) {
            $this->writeln('User-Agent: phpDaemon/' . Daemon::$version);
        }
        if (isset($params['cookie']) && sizeof($params['cookie'])) {
            $this->writeln('Cookie: ' . http_build_query($params['cookie'], '', '; '));
        }
        if (isset($params['contentType'])) {
            if (!isset($params['headers'])) {
                $params['headers'] = [];
            }
            $params['headers']['Content-Type'] = $params['contentType'];
        }
        if (isset($params['headers'])) {
            $this->customRequestHeaders($params['headers']);
        }
        if (isset($params['rawHeaders']) && $params['rawHeaders']) {
            $this->rawHeaders = [];
        }
        if (isset($params['chunkcb']) && is_callable($params['chunkcb'])) {
            $this->chunkcb = $params['chunkcb'];
        }
        $this->writeln('');
        $this->requests->push($type);
        $this->onResponse->push($params['resultcb']);
        $this->checkFree();
    }
793917
public function redirect($url, $message = null, $type = 'success')
	{
		$redirect = new RedirectResponse($url);
		$redirect->setRequest($this['request']);

		if ($message && $this->has('notification'))
		{
			$this['notification']->message($message, $type);
		}

		$redirect->send();

		$this->close();
	}
168713
public function create($token = null)
    {
        if ($token) {
            $this->model->setToken($token);
        }

        return $this->request->create($this->model);
    }
1123394
public function token($name = '__token__', $type = 'md5')
    {
        $type  = is_callable($type) ? $type : 'md5';
        $token = call_user_func($type, $_SERVER['REQUEST_TIME_FLOAT']);
        if ($this->isAjax()) {
            header($name . ': ' . $token);
        }
        Session::set($name, $token);
        return $token;
    }
4440
protected Response performRequest(String url,
			Map<String, String> additionalHeaders) throws IOException {
		if (accessToken == null) {
			throw new UnauthorizedException("Access token has not yet been requested");
		}
		URL u = new URL(url);
		return auth.request(u, Method.GET, accessToken, additionalHeaders);
	}
1051599
private function doApiCall($url, $method, $access_token = null, $parameters = [], $contentType = 'text/xml')
    {
        $request = [];
        $headers = [];

        $request[CURLOPT_TIMEOUT]       = (int) $this->http_timeout;
        $request[CURLOPT_USERAGENT]     = str_replace('%VERSION%', Client::VERSION, $this->http_user_agent);
        $request[CURLOPT_CUSTOMREQUEST] = $method;

        if (isset($parameters['Ocp-Apim-Subscription-Key'])) {
            $headers[] = "Ocp-Apim-Subscription-Key: ".$parameters['Ocp-Apim-Subscription-Key'];
            $headers[] = "Content-Length: 0";
            unset($parameters['Ocp-Apim-Subscription-Key']);
        }

        if (! empty($parameters)) {
            if ($method === 'GET') {
                $url = Tools::httpBuildUrl($url, ["query" => http_build_query($parameters)], Tools::HTTP_URL_JOIN_QUERY);
            } else {
                if (is_array($parameters)) {
                    $request[CURLOPT_POSTFIELDS] = http_build_query($parameters);
                } else {
                    if (is_string($parameters)) {
                        $request[CURLOPT_POSTFIELDS] = $parameters;
                    }
                }
            }
        }

        $request[CURLOPT_URL] = $url;

        if (! is_null($contentType)) {
            $headers[] = "Content-Type: $contentType";
        }

        if (! is_null($access_token)) {
            $headers[] = 'Authorization: Bearer '.$access_token;
        }

        if (! empty($this->http_proxy_host)) {
            $request[CURLOPT_PROXY] = $this->http_proxy_host;

            if (! empty($this->http_proxy_port)) {
                $request[CURLOPT_PROXYPORT] = $this->http_proxy_port;
            }

            if (! empty($this->http_proxy_type)) {
                $request[CURLOPT_PROXYTYPE] = $this->http_proxy_type;
            }

            if (! empty($this->http_proxy_auth)) {
                $request[CURLOPT_PROXYAUTH] = $this->http_proxy_auth;
            }

            if (! empty($this->http_proxy_user)) {
                $request[CURLOPT_PROXYUSERPWD] = $this->http_proxy_user.':'.$this->http_proxy_pass;
            }
        }

        $request[CURLOPT_HTTPHEADER] = $headers;

        $this->logger->info(__CLASS__, 'api', sprintf('%s %s', $method, $url));

        $start = microtime(true);
        @list($result, $status_code, $error, $errno) = $this->execCurl($request);
        $end = microtime(true);

        $duration = (int) round(($end - $start) * 1000);

        if ($errno === 0) {
            $return = [
                'http_code' => $status_code,
                'http_body' => $result,
                'duration'  => $duration,
            ];

            if ($status_code >= 400) {
                $this->logger->error(__CLASS__, 'api', sprintf('Response HTTP code %s, body length %s bytes, duration %sms on endpoint %s %s', $status_code, strlen($result), $duration, $method, $url));
            } else {
                if ($status_code >= 300) {
                    $this->logger->warning(__CLASS__, 'api', sprintf('Response HTTP code %s, body length %s bytes, duration %sms on endpoint %s %s', $status_code, strlen($result), $duration, $method, $url));
                } else {
                    $this->logger->info(__CLASS__, 'api', sprintf('Response HTTP code %s, body length %s bytes, duration %sms', $status_code, strlen($result), $duration));
                }
            }
        } else {
            $return = [
                'error_msg' => $error,
                'error_num' => $errno,
                'duration'  => $duration,
            ];

            $this->logger->error(__CLASS__, 'api', sprintf('cURL error #%s : %s', $errno, $error));
        }

        return $return;
    }
1242223
def _make_request(self, type, path, args, noRetry=False):
        
        response = getattr(requests, type)(path, headers = self._add_auth_headers(_JSON_HEADERS), **args)
        if response.status_code == 200 or response.status_code == 201:
            return response.json()
        elif not noRetry and self._is_expired_response(response) \
          and 'refresh_token' in self.creds:
            try:
                self.exchange_refresh_token()
            except TokenEndpointError:
                raise _rest_error_from_response(response)
            return self._make_request(type, path, args, noRetry = True)
        raise _rest_error_from_response(response)
1091602
public function requestUserData($type = 'private', $access_token = null)
    {
        $config = $this->getConfig();
        $access_token = ($access_token) ? $access_token : $this->getAccessToken();
        $url = null;

        switch ($type) {
            case 'public':
                //error if no profile set
                if (!$this->getPublicProfileUrl()) {
                    throw new \Exception('please set the public profile you want to pull');
                }

                $url = $config['urls']['public']
                    . urlencode(urldecode($this->getPublicProfileUrl()))  // make sure the url is encoded; avoid double encoding
                    . $config['dataset'][$type]['fields'];
                break;
            case 'private':
            case 'login':
            default:
                $url = $config['urls']['private']
                    . $config['dataset'][$type]['fields'];
                break;
        }

        //add access token to request url
        $url .= '?' . http_build_query(array('oauth2_access_token' => $access_token, 'secure-urls' => 'true'));

        //send it
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_VERBOSE, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);  // don't worry about bad ssl certs
        curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept-Language: en-US, ja"));
        $response = curl_exec($ch);

        $data = simplexml_load_string($response);

        return $data;
    }