Generate and return the JWT signature this is made up of the header,
payload and secret.

@return string
@throws Exception\ValidateException
550726
private function getSignature(): string
    {
        if (!empty($this->secret)) {
            return $this->encode->signature(
                $this->jsonEncode($this->getHeader()),
                $this->jsonEncode($this->getPayload()),
                $this->secret
            );
        }

        throw new ValidateException('Invalid secret.', 9);
    }
247868
protected function createAuthorizationHeader(): string
    {
        $username = $this->getOption('api.username');
        $password = $this->getOption('api.password');

        // The API requires HTTP Basic Authentication, we can't proceed without credentials
        if ($username === null || $password === null) {
            throw new \InvalidArgumentException('Missing credentials for API authentication.');
        }

        return 'Basic ' . \base64_encode("$username:$password");
    }
780641
public function getAuthToken()
    {
        if(!isset($this->__token))
        {
            $token   = false;
            $request = $this->getObject('request');

            if($request->headers->has('Authorization'))
            {
                $header = $request->headers->get('Authorization');

                if(stripos($header, 'jwt') === 0) {
                    $token = substr($header , 4);
                }
            }

            if($request->isSafe())
            {
                if($request->query->has('auth_token')) {
                    $token = $request->query->get('auth_token', 'url');
                }
            }
            else
            {
                if($request->data->has('auth_token')) {
                    $token = $request->data->get('auth_token', 'url');
                }
            }

            if($token) {
                $token = $this->getObject('lib:http.token')->fromString($token);
            }

            $this->__token = $token;
        }

        return $this->__token;
    }
1244078
protected function requestAuthorizationToken(): string
    {
        $result = $this->options->getAuthorizationToken();
        if ($result === '') {
            $authRequest = new AuthRequest();
            $authRequest->setAgent($this->options->getAgent())
                        ->setAccessKey($this->options->getAccessKey())
                        ->setEnabledModNames($this->options->getEnabledModNames());

            $authResponse = $this->fetchResponse($authRequest);
            if ($authResponse instanceof AuthResponse) {
                $result = $authResponse->getAuthorizationToken();
                $this->options->setAuthorizationToken($result);
            }
        }
        return $result;
    }
594022
public function serialize(): string
    {
        return serialize([
            $this->password,
            $this->salt,
            $this->usernameCanonical,
            $this->username,
            $this->locked,
            $this->enabled,
            $this->id,
            $this->encoderName,
        ]);
    }
525706
public function getSignHeaderValue()
    {
        $signature = '';
        if (isset($_SERVER['HTTP_X_VIBER_CONTENT_SIGNATURE'])) {
            $signature = $_SERVER['HTTP_X_VIBER_CONTENT_SIGNATURE'];
        } elseif (isset($_GET['sig'])) {
            $signature = $_GET['sig'];
        }
        if (empty($signature)) {
            throw new \RuntimeException('Signature header not found', 1);
        }

        return $signature;
    }
216442
private static function createJWSAndSign($payload, JWKInterface $signature_key, array $protected_headers = [], $headers = [])
    {
        $jws = self::createJWS($payload);

        $jws = $jws->addSignatureInformation($signature_key, $protected_headers, $headers);

        $complete_headers = array_merge($protected_headers, $headers);
        Assertion::keyExists($complete_headers, 'alg', 'No "alg" parameter set in the header');
        $signer = Signer::createSigner([$complete_headers['alg']]);
        $signer->sign($jws);

        return $jws;
    }
632681
public function getTokenString()
    {
        $signinInput = $this->generateSigninInput();

        return sprintf('%s.%s', $signinInput, $this->encoder->encode($this->getSignature()));
    }
623487
private function getSignature(Request $request)
    {
        switch ($this->getSignatureMethod()) {
            case self::SIGNATURE_RSA_SHA1:
                $signature = RSASHA1::generateSignature(
                    $this->config,
                    $this->getSBS($request),
                    $this->getSigningSecret()
                );

                break;
            case self::SIGNATURE_HMAC_SHA1:
                $signature = HMACSHA1::generateSignature(
                    $this->config,
                    $this->getSBS($request),
                    $this->getSigningSecret()
                );

                break;
            case self::SIGNATURE_PLAINTEXT:
                $signature = PLAINTEXT::generateSignature(
                    $this->config,
                    $this->getSBS($request),
                    $this->getSigningSecret()
                );

                break;
            default:
                throw new Exception(
                    "Invalid signature method [{$this->config['signature_method']}]"
                );
        }

        return $signature;
    }
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;
  }
51391
public String generateJwt() throws NexmoUnacceptableAuthException {
        JWTAuthMethod authMethod = this.httpWrapper.getAuthCollection().getAuth(JWTAuthMethod.class);
        return authMethod.constructToken(System.currentTimeMillis() / 1000L, JWTAuthMethod.constructJTI());
    }
666347
public function getToken()
    {
        if ($this->token === null) {
            try {
                $this->parseToken();
            } catch (JWTException $e) {
                $this->token = null;
            }
        }

        return $this->token;
    }
456696
public function encode(JWT $jwt)
    {
        $this->jwt = $jwt;
        $token     = Codec::encode($jwt->getClaims(), $this->secret);

        return $token;
    }
127406
public function build(): JWS
    {
        if (null === $this->payload) {
            throw new \RuntimeException('The payload is not set.');
        }
        if (0 === \count($this->signatures)) {
            throw new \RuntimeException('At least one signature must be set.');
        }

        $encodedPayload = false === $this->isPayloadEncoded ? $this->payload : Base64Url::encode($this->payload);
        $jws = JWS::create($this->payload, $encodedPayload, $this->isPayloadDetached);
        foreach ($this->signatures as $signature) {
            /** @var SignatureAlgorithm $signatureAlgorithm */
            $signatureAlgorithm = $signature['signature_algorithm'];
            /** @var JWK $signatureKey */
            $signatureKey = $signature['signature_key'];
            /** @var array $protectedHeader */
            $protectedHeader = $signature['protected_header'];
            /** @var array $header */
            $header = $signature['header'];
            $encodedProtectedHeader = empty($protectedHeader) ? null : Base64Url::encode($this->jsonConverter->encode($protectedHeader));
            $input = \sprintf('%s.%s', $encodedProtectedHeader, $encodedPayload);
            $s = $signatureAlgorithm->sign($signatureKey, $input);
            $jws = $jws->addSignature($s, $protectedHeader, $encodedProtectedHeader, $header);
        }

        return $jws;
    }
948196
public function parse(): Payload
    {
        /** Check signature from header */
        if (!$this->_checkSignature()) {
            throw new BadSignatureException('Hook secret does not match.');
        }

        /** Get data from different locations according to content-type */
        switch ($this->serverBag->get('CONTENT_TYPE')) {
            case 'application/json':
                $data = $this->getRawData();
                break;

            case 'application/x-www-form-urlencoded':
                $data = $_POST['payload'];
                break;

            default:
                throw new Exception('Unsupported content type: "' . $this->serverBag->get('CONTENT_TYPE') . '"');
        }
        $this->setParsedData($data);

        return $this;
    }
593142
public function encode() : string
    {
        $segments = [
            $this->header->encode(),
            $this->payload->encode(),
            self::base64UrlEncode($this->signature)
        ];

        return implode('.', $segments);
    }
1278609
public function getRequestSignature()
    {
        if (empty($this->requestSignature)) {

            $string = $this->getApiId()
                . $this->getTimeStamp()
                . $this->getNonce()
                . $this->getDataString();

            $this->requestSignature = hash_hmac('sha1', $string, $this->getService()->getApiSecret());
        }

        return $this->requestSignature;
    }