Generate the signature

@param Request[]                     $requests
@param Position                      $position
@param RequestEnvelope\AuthInfo|null $authInfo

@return string
971270
protected function generateSignature(array $requests, Position $position, RequestEnvelope\AuthInfo $authInfo = null) : string
    {

        $authData = $this->ticket instanceof AuthTicket && !$this->ticket->hasExpired() ?
            Hashing\AuthData::withAuthTicket($this->ticket) :
            Hashing\AuthData::withAuthInfo($authInfo);

        $time    = round(microtime(true) * 1000);
        $request = new Hashing\Request(
            $this->version,
            $authData,
            $position,
            $time,
            $this->getSessionHash(),
            $requests
        );

        $response = $this->hashingProvider->calculate($request);

        $signature = new Signature();
        $signature->setLocationHash1($response->getLocationAuthHash());
        $signature->setLocationHash2($response->getLocationHash());

        foreach ($response->getRequestHashes() as $requestHash) {
            $signature->addRequestHash($requestHash);
        }

        $signature->setSessionHash($this->getSessionHash());
        $signature->setTimestamp($time);
        $signature->setTimestampSinceStart($time - $this->startTime);
        $signature->setUnknown25($this->version->getUnknown25());

        $signature->setDeviceInfo($this->deviceInfo->toProtobuf());

        foreach ($this->generateLocationFixes($position) as $fix) {
            $signature->addLocationFix($fix);
        }

        $signature->setSensorInfoList($this->generateSensorInfo());

        return Encrypt::encrypt($signature->toStream()->getContents(), random_bytes(32));
    }
269447
public function generate($method, $url, array $data = [], array $headers = [], $basicAuthCredentials = '')
    {
        $signatureParts = [$method, $url];
        $signatureParts[] = http_build_query($data);
        $signatureParts[] = http_build_query($headers);
        $signatureParts[] = $basicAuthCredentials;

        return implode('|', $signatureParts);
    }
886219
private function generateTokens(ServerRequestInterface $request, $lockTo, array &$tokens)
    {
        $index = self::encode($this->randomToken(18));
        $token = self::encode($this->randomToken(32));

        $tokens[$index] = [
            'uri' => $request->getUri()->getPath(),
            'token' => $token,
            'lockTo' => $lockTo,
        ];

        if ($this->maxTokens > 0 && ($total = count($tokens)) > $this->maxTokens) {
            array_splice($tokens, 0, $total - $this->maxTokens);
        }

        $token = self::encode(hash_hmac('sha256', ClientIp::getIp($request), base64_decode($token), true));

        return '<input type="hidden" name="'.$this->formIndex.'" value="'.htmlentities($index, ENT_QUOTES, 'UTF-8').'">'
               .'<input type="hidden" name="'.$this->formToken.'" value="'.htmlentities($token, ENT_QUOTES, 'UTF-8').'">';
    }
1300814
public function signature($url = null, $nonce = null, $timestamp = null)
    {
        $url = $url ? $url : $this->getUrl();
        $nonce = $nonce ? $nonce : Str::quickRandom(10);
        $timestamp = $timestamp ? $timestamp : time();
        $ticket = $this->ticket();

        $sign = [
            'appId'     => $this->getAccessToken()->getCorpId(),
            'nonceStr'  => $nonce,
            'timestamp' => $timestamp,
            'url'       => $url,
            'signature' => $this->getSignature($ticket, $nonce, $timestamp, $url),
        ];

        return $sign;
    }
323154
public function watermarkPosition(string $position)
    {
        if (! $this->validateManipulation($position, 'position')) {
            throw InvalidManipulation::invalidParameter(
                'watermarkPosition',
                $position,
                $this->getValidManipulationOptions('position')
            );
        }

        return $this->addManipulation('watermarkPosition', $position);
    }
944186
public function stepURL($position)
    {
        $s = 's_'.$position;
        $s = $this->$s;

        return $this->url(null, array('step' => $s));
    }
776642
private void doFormLogin(FormAuthInfo authInfo) {
        logger.info("FORM authentication for: {}", authInfo.getLoginTarget());
        String fullUri =
                authInfo.getProtocol() + "://" + authInfo.getHost() + ":" + authInfo.getPort() +
                        authInfo.getLoginTarget();
        HttpPost httpPost = new HttpPost(fullUri);
        List<NameValuePair> formParams = new ArrayList<>();
        formParams.add(
                new BasicNameValuePair(authInfo.getUsernameFormStr(), authInfo.getUsername()));
        formParams.add(
                new BasicNameValuePair(authInfo.getPasswordFormStr(), authInfo.getPassword()));
        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formParams, StandardCharsets.UTF_8);
        httpPost.setEntity(entity);

        try {
            httpClient.execute(httpPost);
            logger.debug("Successfully request to login in with user: {} to: {}", authInfo.getUsername(),
                    authInfo.getHost());
        } catch (ClientProtocolException e) {
            logger.error("While trying to login to: {} - Client protocol not supported",
                    authInfo.getHost(), e);
        } catch (IOException e) {
            logger.error("While trying to login to: {} - Error making request", authInfo.getHost(),
                    e);
        }
    }
933973
public function validAuthenticationResponse($request, $result)
    {
        if (Str::startsWith($request->channel_name, 'private')) {
            return $this->decodePusherResponse(
                $this->pusher->socket_auth($request->channel_name, $request->socket_id)
            );
        }

        return $this->decodePusherResponse(
            $this->pusher->presence_auth(
                $request->channel_name, $request->socket_id, $request->user()->getAuthIdentifier(), $result)
        );
    }
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);
    }
549571
public function getRequestAuthorization(RequestInterface $request, AccessToken $token):RequestInterface{
		$uri = $request->getUri();

		parse_str($uri->getQuery(), $query);

		$parameters = [
			'oauth_consumer_key'     => $this->options->key,
			'oauth_nonce'            => $this->nonce(),
			'oauth_signature_method' => 'HMAC-SHA1',
			'oauth_timestamp'        => (new DateTime)->format('U'),
			'oauth_token'            => $token->accessToken,
			'oauth_version'          => '1.0',
		];

		$parameters['oauth_signature'] = $this->getSignature(
			(string)$uri->withQuery('')->withFragment(''),
			array_merge($query, $parameters),
			$request->getMethod(),
			$token->accessTokenSecret
		);

		if(isset($query['oauth_session_handle'])){
			$parameters['oauth_session_handle'] = $query['oauth_session_handle'];
		}

		return $request->withHeader('Authorization', 'OAuth '.Psr7\build_http_query($parameters, true, ', ', '"'));
	}
248902
protected function clientSignature(Request $request): string
    {
        $signature = '';
        foreach (static::SIGNATURE_HEADERS as $header) {
            $signature .= $request->getHeaderLine($header) . ';';
        }

        return hash('sha256', $signature);
    }
299025
public function infoAction(Request $request)
    {
        $securityContext = $this->get('security.context');

        $lines = [];

        if ($securityContext->isGranted('ROLE_SUPER_ADMIN')) {
            $lines[] = [
                'Project:',
                $this->container->getParameter('phlexible_gui.project.title').' '
                    .$this->container->getParameter('phlexible_gui.project.version'),
            ];
            $lines[] = [
                'Env:',
                $this->container->getParameter('kernel.environment').($this->container->getParameter(
                    'kernel.debug'
                ) ? ' [DEBUG]' : ''),
            ];
            $lines[] = ['Host:', $request->server->get('SERVER_NAME').' ['.PHP_SAPI.']'];

            $connection = $this->getDoctrine()->getConnection();
            /* @var $connection \Doctrine\DBAL\Connection */

            $lines[] = [
                'Default Database:',
                $connection->getHost().' / '.$connection->getDatabase().' ['.$connection->getDriver()->getName(
                ).']',
            ];

            $lines[] = ['Session:', $request->getSession()->getId().' ['.$request->server->get('REMOTE_ADDR').']'];

            $lines[] = [
                'User:',
                $this->getUser()->getUsername().' ['.implode(', ', $this->getUser()->getRoles()).']',
            ];

            $lines[] = ['UserAgent:', $request->server->get('HTTP_USER_AGENT')];
        } else {
            $lines[] = [
                'Project:',
                $this->container->getParameter('phlexible_gui.project.title').' '
                .$this->container->getParameter('phlexible_gui.project.version'),
            ];
        }

        $l1 = 0;
        $l2 = 0;
        foreach ($lines as $line) {
            if (strlen($line[0]) > $l1) {
                $l1 = strlen($line[0]);
            }
            if (isset($line[1]) && strlen($line[1]) > $l2) {
                $l2 = strlen($line[1]);
            }
        }
        $table = '';
        foreach ($lines as $line) {
            $table .= str_pad($line[0], $l1 + 2);
            $table .= str_pad($line[1], $l2 + 2);
            if (isset($line[2])) {
                $table .= $line[2];
            }
            $table .= PHP_EOL;
        }
        $out = '<pre>'.$table.'</pre>';

        return new Response($out);
    }
468360
public function verifySignedStringRequest(
        RequestInterface $request,
        SigningPublicKey $publicKey
    ): string {
        $verified = $this->verifySignedRequest($request, $publicKey);
        return (string) $verified->getBody();
    }
440576
public function getStringToSign(RequestInterface $request, $timestamp, $nonce)
    {
        $params = $this->getParamsToSign($request, $timestamp, $nonce);

        // Convert booleans to strings.
        $params = $this->prepareParameters($params);

        // Build signing string from combined params
        $parameterString = new QueryString($params);

        $url = Url::factory($request->getUrl())->setQuery('')->setFragment(null);

        return strtoupper($request->getMethod()) . '&'
             . rawurlencode($url) . '&'
             . rawurlencode((string) $parameterString);
    }
723086
public function verify($token, $authyId, $force = false, $action = null): Response
    {
        // Prepare required variables
        $url = $this->api."verify/{$token}/{$authyId}";
        $params = $this->params + ['query' => ['force' => $force ? 'true' : 'false', 'action' => $action]];

        // Verify Authy token
        return new Response($this->http->get($url, $params));
    }
125238
public function produce ($method, $path, $headers, $query, $postData, $secret) {

        $sign = array(
            $secret,
            $method,
            rawurlencode($path),
            rawurlencode($this->sign_headers($headers)),
            rawurlencode($this->sign_params($query)),
            rawurlencode($this->sign_params($postData)),
            $secret
        );

        $sign = implode('&', $sign);

        return strtoupper(md5($sign));
    }
400317
protected function generateSign(array $params_wait_to_sign)
    {
        // 1.
        $sorted = [];
        foreach ($params_wait_to_sign as $key => $item) {
            if (! empty($item)) {
                $sorted[$key] = $item;
            }
        }
        ksort($sorted);

        // 2.
        $decoded_query_string = urldecode(http_build_query($sorted));

        // 3.
        $sign = self::signature($decoded_query_string);

        return $sign;
    }