Composes authorization header.
@param array $params request params.
@param string $realm authorization realm.
@return array authorization header in format: [name => content].
496010
protected function composeAuthorizationHeader(array $params, $realm = '')
    {
        $header = 'OAuth';
        $headerParams = [];
        if (!empty($realm)) {
            $headerParams[] = 'realm="' . rawurlencode($realm) . '"';
        }
        foreach ($params as $key => $value) {
            if (substr_compare($key, 'oauth', 0, 5)) {
                continue;
            }
            $headerParams[] = rawurlencode($key) . '="' . rawurlencode($value) . '"';
        }
        if (!empty($headerParams)) {
            $header .= ' ' . implode(', ', $headerParams);
        }

        return ['Authorization' => $header];
    }
580060
protected function getAccessTokenOptions(array $params)
    {
        $options = ['headers' => ['content-type' => 'application/json']];

        if (self::METHOD_POST === $this->getAccessTokenMethod()) {
            $options['body'] = json_encode($params);
        }

        return $options;
    }
290876
public function requireBasicAuth($check_auth = '', $realm = 'Please enter your username and password')
    {

        $authorized = false;
        if (!isset($_SERVER['PHP_AUTH_USER'])) {
            header('WWW-Authenticate: Basic realm="' . $realm . '"');
            header('HTTP/1.0 401 Unauthorized');
            echo 'You must authenticate to continue';
        } else {

            if (is_callable($check_auth)) {
                $authorized = $check_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
            }

            if (!$authorized) {
                session_unset();
                unset($_SERVER['PHP_AUTH_USER']);
                return $this->requireBasicAuth($check_auth, $realm);
            }
        }

        return $authorized;
    }
1260373
public function to_header() {/*{{{*/
    $out ='Authorization: OAuth realm=""';
    $total = array();
    foreach ($this->parameters as $k => $v) {
      if (substr($k, 0, 5) != "oauth") continue;
      if (is_array($v)) throw new OAuthException('Arrays not supported in headers');
      $out .= ',' . OAuthUtil::urlencode_rfc3986($k) . '="' . OAuthUtil::urlencode_rfc3986($v) . '"';
    }
    return $out;
  }
760541
public function auth($params)
	{
		$requestParams = $this->initRequestParams('auth', $params);
		$this->request('auth', $requestParams);

		return empty($this->error);
	}
1106537
protected function proccessRequest($url, &$params, &$data, $headers){

        $token = isset($params['access_token']) ? $params['access_token'] : '';
        $data['cuid'] = md5($token);

        if($url === $this->asrUrl){
            $data['token'] = $token;
            $data = json_encode($data);
        }else{
            $data['tok'] = $token;
        }

        unset($params['access_token']);
    }
1337874
protected function convertUploadParamsToHeaders($body = null, array $params = [], $verifyChecksum = true)
    {
        $headers = [];

        if ($verifyChecksum) {
            $headers['ETag'] = md5($body);
        }

        $availableParams = [
            'contentType' => 'Content-Type',
            'contentDisposition' => 'Content-Disposition',
            'deleteAfter' => 'X-Delete-After',
            'deleteAt' => 'X-Delete-At',
        ];

        foreach ($availableParams as $key => $header) {
            if (isset($params[$key])) {
                $headers[$header] = $params[$key];
            }
        }

        return $headers;
    }
293057
public function toHeader($realm = null)
    {
        $first = true;
        if ($realm) {
            $out = 'Authorization: OAuth realm="' . OAuthUtil::urlencodeRfc3986($realm) . '"';
            $first = false;
        } else {
            $out = 'Authorization: OAuth';
        }
        
        foreach ($this->parameters as $k => $v) {
            if (substr($k, 0, 5) != "oauth") {
                continue;
            }
            if (is_array($v)) {
                throw new OAuthException('Arrays not supported in headers');
            }
            $out .= ($first) ? ' ' : ',';
            $out .= OAuthUtil::urlencodeRfc3986($k) .
                '="' .
                OAuthUtil::urlencodeRfc3986($v) .
                '"';
            $first = false;
        }
        
        return $out;
    }
1211638
public function withRealm(string $realm): self
    {
        $middleware = clone $this;
        $middleware->realm = $realm;

        return $middleware;
    }
1072644
public function import(array $users = array(), $realm = 'Restricted area')
    {
        //realm must be a string
        Argument::i()->test(2, 'string');
        
        $this->realm = $realm;
        $self = $this;
        
        return function (Registry $request, Registry $response) use ($users, $self) {
            //get digest
            $digest = $request->get('server', 'PHP_AUTH_DIGEST');
            
            //if no digest
            if (empty($digest)) {
                //this throws anyways
                return $self->dialog();
            }
            
            // analyze the PHP_AUTH_DIGEST variable
            $data = $self->digest($digest);
            
            //if no username
            if (!isset($users[$data['username']])) {
                //this throws anyways
                return $self->dialog();
            }
            
            // generate the valid response
            $signature = $self->getSignature($users, $data);
            
            //if it doesnt match
            if ($data['response'] !== $signature) {
                //this throws anyways
                return $self->dialog();
            }
        };
    }
537927
private function withHeaders($request)
  {
    $headers = Config::get('cors.allowedHeaders');
    $methods = Config::get('cors.allowedMethods');
    $exposed = Config::get('cors.exposedHeaders');
    $maxAge  = Config::get('cors.maxAge');

    $request->headers->addMany([
      'Access-Control-Allow-Credentials' => Config::get('cors.supportsCredentials'),
      'Access-Control-Allow-Origin' => '*',
      'Access-Control-Allow-Headers' => implode(', ', $headers),
      'Access-Control-Allow-Methods' => implode(', ', $methods),
    ]);

    if (count($exposed) > 0) {
      $request->headers->add('Access-Control-Exposed-Headers', implode(', ', $exposed));
    }

    if ($maxAge > 0) {
      $request->headers->add('Access-Control-Max-Age', $maxAge);
    }
  }
31593
protected function getAccessTokenRequest(array $params)
    {
        $request = parent::getAccessTokenRequest($params);
        $uri = $request->getUri()
            ->withUserInfo($this->clientId, $this->clientSecret);

        return $request->withUri($uri);
    }
871645
public function digestAuth($realm, array $users)
    {
        if ($this->isCLIRequest()) {
            return;
        }

        if (empty($_SERVER['PHP_AUTH_DIGEST'])) {
            $this->sendAuthenticateHeader($realm);

            exit();
        }

        if (!($data = $this->httpDigestParse($_SERVER['PHP_AUTH_DIGEST'])) || !isset($users[$data['username']])) {
            $this->sendAuthenticateHeader($realm);

            exit();
        }

        $A1 = md5($data['username'] . ':' . $realm . ':' . $users[$data['username']]);
        $A2 = md5($_SERVER['REQUEST_METHOD'] . ':' . $data['uri']);

        $valid_response = md5($A1 . ':' . $data['nonce'] . ':' . $data['nc'] . ':' . $data['cnonce'] . ':' . $data['qop'] . ':' . $A2);

        if ($data['response'] != $valid_response) {
            $this->sendAuthenticateHeader($realm);

            exit();
        }
    }
316319
public function getAuthorizationCode(array $params)
	{
		if (isset($params['transaction_state'])) {
			$params['transaction_state'] = json_encode($params['transaction_state']);
		}

		return $this->post('access/getAuthorizationCode', $params);
	}
1124084
protected function buildAuthorizationHeaderForTokenRequest(array $extraParameters = [])
    {
        $parameters = $this->getBasicAuthorizationHeaderInfo();
        $parameters = array_merge($parameters, $extraParameters);
        $parameters[ 'oauth_signature' ] = $this->signature->getSignature(
            $this->getRequestTokenEndpoint(),
            $parameters,
            'POST'
        );

        $authorizationHeader = 'OAuth ';
        $delimiter = '';
        foreach ($parameters as $key => $value) {
            $authorizationHeader .= $delimiter . rawurlencode($key) . '="' . rawurlencode($value) . '"';

            $delimiter = ', ';
        }

        return $authorizationHeader;
    }
236331
public function post($request, $data = null, $params = null) {
        if (is_string ($request)) {
            $request = array(
                "uri" => $request,
                "data" => $data,
                "params" => $params
            );
        }

        $request["params"] = isset ($request["params"]) && is_array ($request["params"]) ? $request["params"] : array();

        if (!isset ($request["authenticate"]) || $request["authenticate"] !== false) {
            $request["params"]["access_token"] = $this->get_access_token();
        }

        $result = MPRestClient::post($request);
        return $result;
    }
351129
public function setAuthHeader($params)
    {
        if (is_array($params)) {
            $this->authHeader = $this->toHeader($params);
        } else {
            if (strpos($params, 'Authorization: ') !== false) {
                $params = str_replace('Authorization: ', '', $params);
            }

            $this->authHeader = $params;
        }
    }