Signs the request with the credentials.

@param RequestInterface $request
@param Credentials $credentials
@return RequestInterface
351439
public static function sign(RequestInterface $request, Credentials $credentials)
    {
        /**
         * @var RequestInterface $request
         */

        $signatureHeaders   = [];
        $base64Md5          = '';
        $contentLength      = '';

        if ($request->getBody()->getSize() !== 0) {
            $base64Md5 = Hmac::md5HashBase64(
                $request->getBody()
                    ->getContents()
            );

            $contentLength = strlen((string)$request->getBody());
            $signatureHeaders = array_merge(
                $signatureHeaders,
                [
                    'content-type'      => $request->getHeader('content-type'),
                    'content-md5'       => $base64Md5,
                    'content-length'    => $contentLength
                ]);
        }

        $parsedUrl = parse_url($request->getUri());
        $targetUrl = $parsedUrl["path"];
        if (!empty($parsedUrl["query"])) {
            $targetUrl = $targetUrl . "?" . $parsedUrl["query"];
        }

        $requestLine = $request->getMethod() . " " . $targetUrl . " HTTP/1.1";

        $signatureHeaders['date'] = $date = gmdate("D, d M Y H:i:s", time()) . " GMT";
        $signatureHeaders['request-line'] = $requestLine;

        $headersString      = Hmac::getHeadersString($signatureHeaders);
        $signatureString    = Hmac::getSignatureString($signatureHeaders);
        $signatureHash      = Hmac::shaHashBase64($signatureString, $credentials->getSecret());
        $authHeader         = sprintf(
            'hmac username="%s", algorithm="hmac-%s", headers="%s", signature="%s"',
            $credentials->getAccessKey(),
            Hmac::ALGORITHM_SHA256,
            $headersString,
            $signatureHash
        );

        $request = $request->withHeader('Authorization', $authHeader)
            ->withHeader('Date', $date);

        if ($request->getBody()->getSize()) {
            return $request->withHeader('Content-Type', $request->getHeader('content-type'))
                ->withHeader('Content-MD5', $base64Md5)
                ->withHeader('Content-Length', $contentLength);
        }

        return $request;
    }
661097
protected function insertCredentials($request) {
		$request->setData('Username', $this->api_username);
		$request->setData('Password', $this->api_password);

		$signature = $this->signMerchantRequest($request);
		if($signature === FALSE) {
			return FALSE;
		}
		$request->setParam('Signature', $signature);

		return TRUE;
	}
1316945
private function query(RequestInterface $request)
    {
        return $this->client->send($request, array_merge(
            [RequestOptions::HTTP_ERRORS => false],
            $this->clientOptions
        ));
    }
571983
public function signRequest(RequestInterface $request, $forceNew = false)
    {
        try {
            // force-get a new token if it was requested, if not, the regular
            // caching mechanism will be used so the call is not necessary here.
            if (true === $forceNew) {
                $this->pool->getToken($forceNew);
            }

            // create a new request with the new uri and the token added to the headers
            $uri = Uri::resolve(
                new Uri($this->pool->getEndpointUrl()),
                $request->getUri()
            );

            return $request
                ->withUri($uri)
                ->withHeader('X-Auth-Token', $this->pool->getTokenId())
            ;
        } catch (TokenException $e) {
            throw new ClientException('Could not obtain token', $request, null, $e);
        }
    }
1097450
public function getCredentials(Request $request)
    {
        $token = !empty($request->headers->get(self::AUTHORIZATION_HEADER)) ?
            $request->headers->get(self::AUTHORIZATION_HEADER) :
            $request->cookies->get(AuthResponseService::AUTH_COOKIE);

        return new CredentialTokenModel(str_replace(self::BEARER, '', $token));
    }
792349
public function authenticate(RequestInterface $request)
    {
        $token = $this->token();

        if (!$token && !$this->findMatchingArea($request)) {
            return $this;
        }

        if (!$token) {
            throw new AuthenticationException('Unable to authenticate, token is missing');
        }

        foreach ($this->providers as $provider) {
            if (!$provider->supportsToken($token)) {
                continue;
            }

            if (!$provider->authenticate($token)) {
                $this->stash()
                     ->destroy();

                throw new AuthenticationException(sprintf('Token could not be authenticated in provider "%s", destroying token', get_class($provider)));
            }

            $this->user = $provider->get($token);

            return $this;
        }

        $this->stash()
             ->destroy();

        throw new AuthenticationException(sprintf('Missing provider supporting token "%s", destroying token', get_class($token)));
    }
992895
protected function authRedirect(RequestInterface $request)
    {
        unset($request);
        // Test if authentication is required.
        if ($this->authRequired() === false) {
            return;
        }

        // Test if user is authorized to access this controller
        if ($this->isAuthorized() === true) {
            return;
        }

        header('HTTP/1.0 403 Forbidden');
        exit;
    }
1203047
public function authentication(Request $request, array $credentials)
    {
        if (!isset($credentials['username'], $credentials['password'])) {
            return $request;
        }
        if (!isset($credentials['realm'])) {
            $credentials = $this->_getServerInfo($request, $credentials);
        }
        if (!isset($credentials['realm'])) {
            return $request;
        }
        $value = $this->_generateHeader($request, $credentials);

        return $request->withHeader('Authorization', $value);
    }
924720
public function init(RequestInterface $request)
    {
        $translator = $this->translator();

        $notice = $request->getParam('notice');
        switch ($notice) {
            case 'resetpass':
                $message = $translator->translate('Check your email for instructions to reset your password.');
                $this->addFeedback([
                    'level'       => 'notice',
                    'message'     => $message,
                    'dismissible' => false
                ]);
                break;

            case 'newpass':
                $message = $translator->translate('Log in with your new password.');
                $this->addFeedback([
                    'level'       => 'notice',
                    'message'     => $message,
                    'dismissible' => false
                ]);
                break;
        }

        return true;
    }
1163679
public function sign(Request $request)
  {
    // add the developer key to the request before signing it
    if ($this->client->getClassConfig($this, 'developer_key')) {
      $request->setQueryParam('key', $this->client->getClassConfig($this, 'developer_key'));
    }

    // Cannot sign the request without an OAuth access token.
    if (null == $this->token && null == $this->assertionCredentials) {
      return $request;
    }

    // Check if the token is set to expire in the next 30 seconds
    // (or has already expired).
    if ($this->isAccessTokenExpired()) {
      if ($this->assertionCredentials) {
        $this->refreshTokenWithAssertion();
      } else {
        $this->client->getLogger()->debug('OAuth2 access token expired');
        if (! array_key_exists('refresh_token', $this->token)) {
          $error = "The OAuth 2.0 access token has expired,"
                  ." and a refresh token is not available. Refresh tokens"
                  ." are not returned for responses that were auto-approved.";

          $this->client->getLogger()->error($error);
          throw new Exception($error);
        }
        $this->refreshToken($this->token['refresh_token']);
      }
    }

    $this->client->getLogger()->debug('OAuth2 authentication');

    // Add the OAuth2 header to the request
    $request->setRequestHeaders(
        array('Authorization' => 'Bearer ' . $this->token['access_token'])
    );

    return $request;
  }
69287
private function appendHeaders(RequestInterface $request)
    {
        $headers = $this->auth->getHeaders();
        foreach ($headers as $key => $value) {
            $request = $request->withHeader($key, $value);
        }
        return $request;
    }
722551
public function sign(Google_HttpRequest $request) {
    // add the developer key to the request before signing it
    if ($this->developerKey) {
      $requestUrl = $request->getUrl();
      $requestUrl .= (strpos($request->getUrl(), '?') === false) ? '?' : '&';
      $requestUrl .=  'key=' . urlencode($this->developerKey);
      $request->setUrl($requestUrl);
    }

    // Cannot sign the request without an OAuth access token.
    if (null == $this->token && null == $this->assertionCredentials) {
      return $request;
    }

    // Check if the token is set to expire in the next 30 seconds
    // (or has already expired).
    if ($this->isAccessTokenExpired()) {
      if ($this->assertionCredentials) {
        $this->refreshTokenWithAssertion();
      } else {
        if (! array_key_exists('refresh_token', $this->token)) {
            throw new Google_AuthException("The OAuth 2.0 access token has expired, "
                . "and a refresh token is not available. Refresh tokens are not "
                . "returned for responses that were auto-approved.");
        }
        $this->refreshToken($this->token['refresh_token']);
      }
    }

    // Add the OAuth2 header to the request
    $request->setRequestHeaders(
        array('Authorization' => 'Bearer ' . $this->token['access_token'])
    );

    return $request;
  }
1171746
public function sign(Request $request)
  {
    if ($this->isAccessTokenExpired()) {
      $this->acquireAccessToken();
    }

    $this->client->getLogger()->debug('Compute engine service account authentication');

    $request->setRequestHeaders(
        array('Authorization' => 'Bearer ' . $this->token['access_token'])
    );

    return $request;
  }
444690
protected function getCacheKey(RequestInterface $request): string
    {
        if ($this->key === null) {
            $this->key = $request->getMethod() . md5((string)$request->getUri());
        }
        return (string)$this->key;
    }
1061223
protected function signRequest($request)
    {
        $url = $request->getUrl(true);
        $url->getQuery()->add('key', $this->key);

        $request->setUrl($url);
    }
1302191
protected function createUrl(RequestInterface $request)
    {
        $query = $request->buildQuery();

        if ($this->hasKey()) {
            $query['key'] = $this->key;
        }

        $url = $this->createBaseUrl($request).'?'.http_build_query($query, '', '&');

        if ($this->hasBusinessAccount()) {
            $url = $this->businessAccount->signUrl($url);
        }

        return $url;
    }
425106
protected function signRequest(HttpRequest $request, $username, $timestamp, $secretKey)
    {
        $message = $username
                 . $timestamp
                 . $this->getRequestMessage($request)
        ;

        return $this->algorithm->sign($message, $secretKey);
    }