Builds request options used for requesting an access token.

@param array $params

@return array
327509
protected function getAccessTokenOptions(array $params)
    {
        $options = parent::getAccessTokenOptions($params);
        $options['headers']['Authorization'] =
            'Basic '.base64_encode($this->clientId.':'.$this->clientSecret);

        return $options;
    }
61298
protected function createPreOneTwentySeven( $params ) {
		$newParams = [
			'name' => $params['username'],
			'password' => $params['password'],
		];
		if ( array_key_exists( 'email', $params ) ) {
			$newParams['email'] = $params['email'];
		}
		// First get the token.
		$tokenRequest = new SimpleRequest( 'createaccount', $newParams );
		$result = $this->api->postRequest( $tokenRequest );
		if ( $result['createaccount']['result'] == 'NeedToken' ) {
			// Then send the token to create the account.
			$newParams['token'] = $result['createaccount']['token'];
			$request = new SimpleRequest( 'createaccount', $newParams );
			$result = $this->api->postRequest( $request );
		}
		return ( $result['createaccount']['result'] === 'Success' );
	}
1347505
protected function buildQuery(array $queryParams = [])
    {
        $auth = [
            'appId' => $this->config['appId'],
            'appKey' => $this->config['appKey'],
        ];

        $queryParams = array_merge($auth, $queryParams);

        if (isset($queryParams['extendedOptions'])) {
            $extendedOptions = $queryParams['extendedOptions'];
        } else {
            $extendedOptions = [];
        }

        if (!is_array($extendedOptions)) {
            $extendedOptions = [$extendedOptions];
        }

        if ($this->config['use_http_errors'] &&
            !in_array('useHTTPErrors', $extendedOptions)
        ) {
            $extendedOptions[] = 'useHTTPErrors';
        }

        $queryParams['extendedOptions'] = implode('+', $extendedOptions);

        return $queryParams;
    }
809125
protected function getAccessTokenOptions(array $params)
    {
        // Add params that are required
        $params += [
            'scope' => implode($this->getScopeSeparator(), $this->getDefaultScopes()),
        ];

        $options = parent::getAccessTokenOptions($params);

        // Add authorization header
        $options['headers']['Authorization'] = sprintf(
            'Basic %s',
            base64_encode(
                sprintf(
                    '%s:%s',
                    $this->clientId,
                    $this->lif
                )
            )
        );

        return $options;
    }
1174186
public function withServerParams(array $params)
    {
        $request = $this->copy();
        $request->serverParams = $params;
        
        $request->reset();
        
        return $request;
    }
391853
protected function buildAuthenticator($params = array())
    {
        $signature = new Signature($this->networkKey);
        $signature->getNoncer()->setLength(self::NONCE_LENGTH);

        $authenticator = array(
            'identifier' => $this->networkId,
            'time' => $signature->getRequestTime(),
            'hash' => $signature->generate($params),
            'nonce' => $signature->getNonce(),
        );

        return $authenticator;
    }
658504
protected function prepareParams(array $params)
    {
        foreach ($params as $key => $param) {
            if (gettype($param) === 'boolean') {
                $params[$key] = (string)(($param) ? 'true' : 'false');
            }
        }
        return $params;
    }
1011237
protected function parseTokens(array $tokens) : Request
    {
        $request = new Request();
        $hasParsedCommandName = false;

        while ($token = array_shift($tokens)) {
            if (mb_strpos($token, '--') === 0) {
                $option = $this->parseLongOption($token, $tokens);
                $request->addOptionValue($option[0], $option[1]);
            } elseif (mb_substr($token, 0, 1) === '-') {
                $options = $this->parseShortOption($token);

                foreach ($options as $option) {
                    $request->addOptionValue($option[0], $option[1]);
                }
            } else {
                if (!$hasParsedCommandName) {
                    // We consider this to be the command name
                    $request->setCommandName($token);
                    $hasParsedCommandName = true;
                } else {
                    // We consider this to be an argument
                    $request->addArgumentValue($this->parseArgument($token));
                }
            }
        }

        return $request;
    }
916581
public function options(array $params) {
        $schema = new Garp_Content_Api_Rest_Schema('rest');
        if (!array_get($params, 'datatype')) {
            $out = array();
            $out['root'] = (string)new Garp_Util_FullUrl(array(array(), 'rest'));
            $out['i18n'] = array(
                'locales' => Garp_I18n::getLocales(),
                'default' => Garp_I18n::getDefaultLocale()
            );

            $out['urls'] = $this->_getUrlsForOptions();

            $out['models'] = $schema->getModelPaths();
            return $this->_formatResponse($out, 200);
        }
        if (array_get($params, 'id') || array_get($params, 'relatedType')) {
            return $this->_formatResponse(null, 200, false);
        }
        return $this->_formatResponse($schema->getModelDetails($params['datatype']), 200);
    }
559333
private function request(RequestParams $params)
    {
        /*
         * Build Resource URI
         */
        $rm = $params->resourceMetadata;
        $base = $this->config['base_url'] . $this->config['api_path'] . "/";

        if (!empty($params->appId)) {
            $url = $base . 'General/Apps/' . $params->appId . '/callBackend';
        } else {
            $url = $base . $rm->product . '/' . $rm->resource;
        }

        if (!empty($params->id)) {
            $url .= '/' . $params->id;
        }

        if (!empty($params->action)) {
            $url .= '/' . $params->action;
        }

        if (!empty($params->actionArg)) {
            $url .= '/' . $params->actionArg;
        }

        $options = array_merge(['auth' => 'oauth'], $params->options);

        if (!array_key_exists(\GuzzleHttp\RequestOptions::HEADERS, $options)) {
            $options[\GuzzleHttp\RequestOptions::HEADERS] = [];
        }

        /*
         * Result filtering, sorting & searching
         */
        $p = [];
        if (!empty($params->searchParams->query)) {
            $q = $params->searchParams->query;

            if (!empty($q->count)) {
                $p['count'] = $q->count;
            }

            if (!empty($q->offset)) {
                $p['offset'] = $q->offset;
            }

            if (!empty($q->query)) {
                $p['q'] = $q->query;
            }

            if (!empty($q->fields)) {
                $p['fields'] = implode(',', $q->fields);
            }

            if (!empty($q->sortOrder)) {
                foreach ($q->sortOrder as $key => $value) {
                    $p['sort[' . $key . ']'] = $value;
                }
            }
        }

        if (!empty($params->searchParams->scrollId)) {
            $p['scroll_id'] = $params->searchParams->scrollId;
        }

        if (!empty($params->searchParams->scrollExpire)) {
            $p['scroll_expire'] = $params->searchParams->scrollExpire;
        }

        if (count($p) != 0) {
            $options[\GuzzleHttp\RequestOptions::QUERY] = $p;
        }

        /*
         * JSON Body
         */

        if (!empty($params->jsonData)) {
            $options[\GuzzleHttp\RequestOptions::BODY] = $params->jsonData;
            $options[\GuzzleHttp\RequestOptions::HEADERS]['Content-Type'] = 'application/json';
        }

        /*
         * Idempotence (avoid double execution of the same request)
         */
        if ($this->actionId !== null) {
            $options[\GuzzleHttp\RequestOptions::HEADERS]['X-Action'] = $this->actionId;
            $this->setActionId(null);
        }

        /*
         * Run request
         */
        try {
            $response = $this->httpClient->request($params->operation, $url, $options);
        } catch (Exception $e) {
            throw $this->mapError($e, 'Error sending API request.');
        }

        if ($response->getStatusCode() == 200) {
            return MapperUtil::mapResponse($response);
        }

        return false;
    }
769110
public function params($requestParams): array
    {
        // apply type and default value for request params
        $params = [];
        foreach ($this->params as $param => $type) {
            if (isset($requestParams[$param])) {
                switch ($type) {
                    case 'bool':
                    case 'boolean':
                        $params[] = (bool)$requestParams[$param];
                        break;
                    case 'int':
                    case 'integer':
                        $params[] = (int)$requestParams[$param];
                        break;
                    case 'float':
                        $params[] = (float)$requestParams[$param];
                        break;
                    case 'string':
                        $params[] = (string)$requestParams[$param];
                        break;
                    case 'array':
                        $params[] = (array)$requestParams[$param];
                        break;
                    default:
                        $params[] = $requestParams[$param];
                        break;
                }
            } elseif (isset($this->values[$param])) {
                $params[] = $this->values[$param];
            } else {
                $params[] = null;
            }
        }
        return $params;
    }
133914
private function getToken($accessTokenParams)
    {
        $kvs = $this->getKeyValueStorage();

        if ($kvs->has(self::ACCESS_TOKEN_KEY) && $kvs->has(self::REFRESH_TOKEN_KEY)) {
            return new AccessToken([
                'access_token' => $kvs->get(self::ACCESS_TOKEN_KEY),
                'expires_in' => $kvs->getTtl(self::ACCESS_TOKEN_KEY),
                'refresh_token' => $kvs->get(self::REFRESH_TOKEN_KEY),
            ]);
        }

        $accessToken = $this->provider->getAccessToken($this->type, $accessTokenParams);
        $this->cacheToken($accessToken);

        return $accessToken;
    }
486470
protected function calculateOptionsForParams(string $requestMethod, array $params, string $accessToken): array
    {
        $options = $this->prepareBaseOptions($accessToken);
        if (0 === \count($params)) {
            return $options;
        }

        switch ($requestMethod) {
            case RequestMethodEnum::GET:
            case RequestMethodEnum::DELETE:
                $options['query'] = $params;
                break;
            case RequestMethodEnum::PUT:
            case RequestMethodEnum::POST:
                $options['form_params'] = $params;
                break;
            case RequestMethodEnum::UPLOAD:
                if (array_key_exists('resource', $params) && array_key_exists('name', $params)) {
                    $options['headers']['X-File-Name'] = $params['name'];
                    $options['multipart'] = [
                        [
                            'contents' => $params['resource'],
                            'name' => $params['name'],
                        ],
                    ];
                }
                break;
            default:
                throw new \InvalidArgumentException(sprintf('Request method "%s" not allowed!', $requestMethod));
        }

        return $options;
    }
716088
public function get($endpoint, $params = [])
    {
        // build url
        $url = $this->domain . '/' . $endpoint;

        if (!empty($params)) {
            $url = $url . '?' . http_build_query($params);
        }

        $request = new Request($url);
        
        // Add client secret header
        if (isset($this->config['secret'])) {
            $request->headers->add(['X-Client-Secret' => $this->config['secret']]);
        }
        
        // add curl options
        if (isset($this->config['curl']) && is_array($this->config['curl'])) {
            foreach ($this->config['curl'] as $option => $value) {
                $request->setOption($option, $value);
            }
        }
        
        $request->execute();

        return $request->getResponse();
    }
172920
protected function getAccessTokenUrl(array $params)
    {
        $url = $this->getBaseAccessTokenUrl($params);

        if ($this->getAccessTokenMethod() === self::METHOD_GET) {
            $query = $this->getAccessTokenQuery($params);
            return $this->appendQuery($url, $query);
        }

        return $url;
    }
334245
protected function getClientParams( array $params, array $prefixes = array( 'f', 'l', 'd', 'a' ) )
	{
		$list = [];

		foreach( $params as $key => $value )
		{
			if( in_array( $key[0], $prefixes ) && $key[1] === '_' ) {
				$list[$key] = $value;
			}
		}

		return $list;
	}
458597
public function loadParams(array $params)
    {
        $this->arguments = array();
        $this->options = array();

        foreach ($params as $param) {
            if (strpos($param, '-') !== false) {
                $this->options[] = $this->extractOption($param);
            } else {
                $this->arguments[] = $param;
            }
        }

        return $this;
    }