Create a JSON Web Token.

@param  array  $payload

@throws \Afroware\JwTauth\Exceptions\JwTException

@return string
481823
public function encode(array $payload)
    {
        try {
            $this->jws->setPayload($payload)->sign($this->getSigningKey(), $this->getPassphrase());

            return (string) $this->jws->getTokenString();
        } catch (Exception $e) {
            throw new JwTException('Could not create token: '.$e->getMessage(), $e->getCode(), $e);
        }
    }
365772
public function create(string $payload, array $signatures, string $jws_serialization_mode, array $jweSharedProtectedHeader, array $jweSharedHeader, array $recipients, string $jwe_serialization_mode, ?string $aad = null): string
    {
        $jws = $this->jwsBuilder->create()->withPayload($payload);
        foreach ($signatures as $signature) {
            if (!\is_array($signature) || !\array_key_exists('key', $signature)) {
                throw new \InvalidArgumentException('The signatures must be an array of arrays containing a key, a protected header and a header');
            }
            $signature['protected_header'] = \array_key_exists('protected_header', $signature) ? $signature['protected_header'] : [];
            $signature['header'] = \array_key_exists('header', $signature) ? $signature['header'] : [];
            $jws = $jws->addSignature($signature['key'], $signature['protected_header'], $signature['header']);
        }
        $jws = $jws->build();
        $token = $this->jwsSerializerManager->serialize($jws_serialization_mode, $jws);

        $jweSharedProtectedHeader['cty'] = 'JWT';

        $jwe = $this->jweBuilder
            ->create()
            ->withPayload($token)
            ->withSharedProtectedHeader($jweSharedProtectedHeader)
            ->withSharedHeader($jweSharedHeader)
            ->withAAD($aad);
        foreach ($recipients as $recipient) {
            if (!\is_array($recipient) || !\array_key_exists('key', $recipient)) {
                throw new \InvalidArgumentException('The recipients must be an array of arrays containing a key and a header');
            }
            $recipient['header'] = \array_key_exists('header', $recipient) ? $recipient['header'] : [];
            $jwe = $jwe->addRecipient($recipient['key'], $recipient['header']);
        }
        $jwe = $jwe->build();
        $token = $this->jweSerializerManager->serialize($jwe_serialization_mode, $jwe);

        return $token;
    }
516846
public function format($payload)
    {
        $payload = $this->fill($payload);
        return "[".$payload['responsecode']."] ".$payload['message']."<br />".$payload['verbosemessage']."<br/>".$payload['url'];

    }
778284
public static function encode($payload, $key, $algo = 'HS256', $additionalHeaders = array()) {
        $header = array('typ' => 'JWT', 'alg' => $algo);
        $header = $header + $additionalHeaders;

        $segments = array();
        $segments[] = self::urlsafeB64Encode(self::jsonEncode($header));
        $segments[] = self::urlsafeB64Encode(self::jsonEncode($payload));
        $signing_input = implode('.', $segments);

        $signature = self::sign($signing_input, $key, $algo);
        $segments[] = self::urlsafeB64Encode($signature);

        return implode('.', $segments);
    }
265511
public static function create(array $payload)
    {
        $referral = isset($payload['referral']) ? Referral::create($payload['referral']) : null;

        return new static($payload['payload'], $referral);
    }
118265
public function update(array $payload): Response
    {
        $this->requiresAccessToken();

        return $this->sendJson(
            'PATCH', 'profile', $this->getApiHeaders(), $this->mergeApiBody($payload)
        );
    }
89042
public function deserializeToken($payload)
  {
    try {
      $payload = str_replace(array('-', '_'), array('+', '/'), $payload);
      $data = $this->encrypter->decrypt($payload);
    } catch (DecryptException $e) {
      return null;
    }

    if(empty($data['id']) || empty($data['key'])) {
      return null;
    }

    $token = $this->generateAuthToken($data['key']);
    $token->setAuthIdentifier($data['id']);

    return $token;
  }
55626
public static function create(array $payload)
    {
        // MessageEvent & MessageEchoEvent
        if (isset($payload['message'])) {
            if (isset($payload['message']['is_echo'])) {
                return self::createMessageEchoEvent($payload);
            }

            return self::createMessageEvent($payload);
        }
        
        // PostbackEvent
        if (isset($payload['postback'])) {
            return self::createPostbackEvent($payload);
        }

        // AuthenticationEvent
        if (isset($payload['optin'])) {
            return self::createAuthenticationEvent($payload);
        }

        // AccountLinkingEvent
        if (isset($payload['account_linking'])) {
            return self::createAccountLinkingEvent($payload);
        }

        // MessageDeliveryEvent
        if (isset($payload['delivery'])) {
            return self::createMessageDeliveryEvent($payload);
        }

        // MessageReadEvent
        if (isset($payload['read'])) {
            return self::createMessageReadEvent($payload);
        }

        // ReferralEvent
        if(isset($payload['referral'])) {
            return self::createReferralEvent($payload);
        }

        return new RawEvent($payload['sender']['id'], $payload['recipient']['id'], $payload);
    }
885017
private function httpPost( $path, Array $payload ){

        $url = new Uri( $this->baseUrl . $path );

        $request = new Request(
            'POST',
            $url,
            $this->buildHeaders(),
            json_encode( $payload )
        );

        try {

            $response = $this->getHttpClient()->sendRequest( $request );

        } catch (\RuntimeException $e){
            throw new Exception\NotifyException( $e->getMessage(), $e->getCode(), $e );
        }

        //---

        switch( $response->getStatusCode() ){
            case 200:
            case 201:
                return $this->handleResponse( $response );
            default:
                return $this->handleErrorResponse( $response );
        }

    }
1052599
public static function createFromPayload(array $payload)
    {
        $job = $payload['job'];
        $data = $payload['data'];

        unset($payload['job'], $payload['data']);

        return new static($job, $data, [], $payload);
    }
318783
private function makeSignedJwt($payload) {
    $header = array('typ' => 'JWT', 'alg' => 'RS256');

    $segments = array(
      Google_Utils::urlSafeB64Encode(json_encode($header)),
      Google_Utils::urlSafeB64Encode(json_encode($payload))
    );

    $signingInput = implode('.', $segments);
    $signer = new Google_P12Signer($this->privateKey, $this->privateKeyPassword);
    $signature = $signer->sign($signingInput);
    $segments[] = Google_Utils::urlSafeB64Encode($signature);

    return implode(".", $segments);
  }
475368
public static function create(array $payload): self
    {
        $senderId = $payload['sender']['id'];
        $recipientId = $payload['recipient']['id'];
        $timestamp = $payload['timestamp'];
        $read = Read::create($payload['read']);

        return new static($senderId, $recipientId, $timestamp, $read);
    }
3992
public static function createMessageEchoEvent(array $payload)
    {
        $message = MessageEcho::create($payload['message']);
        $senderId = $payload['sender']['id'];
        $recipientId = $payload['recipient']['id'];
        $timestamp = $payload['timestamp'];

        return new MessageEchoEvent($senderId, $recipientId, $timestamp, $message);
    }
994908
public static function create(array $payload): self
    {
        $senderId = $payload['sender']['id'];
        $recipientId = $payload['recipient']['id'];
        $timestamp = $payload['timestamp'];
        $payment = Payment::create($payload['payment']);

        return new static($senderId, $recipientId, $timestamp, $payment);
    }
1292865
protected function createToken($data)
    {
        $key = self::getJwtKey();

        $token = array(
            "iat" => time(),
            "provider" => get_class($this),
            "category" => $this->category,
            "data" => $data
        );

        $jwt = JWT::encode($token, $key);

        return $jwt;
    }
169670
protected function parsePayload($payloadJson)
    {
        $claims = [];
        $payload = json_decode($payloadJson, true);

        if (!is_array($payload)) {
            throw new \InvalidArgumentException('Not a valid payload of JWT string passed for deserialization');
        }

        foreach ($payload as $name => $value) {
            $claim = $this->claimFactory->get($name);
            $claim->setValue($value);
            $claims[] = $claim;
        }

        return $claims;
    }
1009524
public function encode(array $payload, array $header = [])
    {
        $header = ['typ' => 'JWT', 'alg' => $this->algo] + $header;

        $this->validateKid($header);

        if (!isset($payload['iat']) && !isset($payload['exp'])) {
            $payload['exp'] = ($this->timestamp ?: \time()) + $this->maxAge;
        }

        $header    = $this->urlSafeEncode($header);
        $payload   = $this->urlSafeEncode($payload);
        $signature = $this->urlSafeEncode($this->sign($header . '.' . $payload));

        return $header . '.' . $payload . '.' . $signature;
    }