@param string $jwt

@return Token
@throws \InvalidArgumentException
485035
public function deserialize($jwt)
    {
        $token = new Token();

        if (empty($jwt)) {
            throw new \InvalidArgumentException('Not a valid JWT string passed for deserialization');
        }

        list($encodedHeader, $encodedPayload, $encodedSignature) = array_pad(explode('.', $jwt, 3), 3, null);

        $decodedHeader    = $this->encoding->decode($encodedHeader);
        $decodedPayload   = $this->encoding->decode($encodedPayload);
        $decodedSignature = $this->encoding->decode($encodedSignature);

        foreach ($this->parseHeaders($decodedHeader) as $header) {
            $token->addHeader($header);
        }

        foreach ($this->parsePayload($decodedPayload) as $claim) {
            $token->addClaim($claim);
        }

        $token->setSignature($decodedSignature);

        return $token;
    }
662482
protected function requireToken($token)
    {
        if ($token) {
            return $this->setToken($token);
        } elseif ($this->token) {
            return $this;
        } else {
            throw new JWTException('A token is required', 400);
        }
    }
311609
public function encode(array $payload)
    {
        try {
            $this->jws->setPayload($payload)->sign($this->secret);

            return $this->jws->getTokenString();
        } catch (Exception $e) {
            throw new JWTException('Could not create token: '.$e->getMessage());
        }
    }
279017
public function createToken(string $tokenSalt): Token
    {
        $this->setToken(Token::create($this, $tokenSalt));
        return $this->token();
    }
785510
public static function generateToken($payload = null)
    {
        if (empty($payload)) {
            return false;
        }

        $token = JWT::encode($payload, Configure::read('ApiRequest.jwtAuth.cypherKey'), Configure::read('ApiRequest.jwtAuth.tokenAlgorithm'));

        return $token;
    }
1008851
public function load(string $token, JWKSet $encryptionKeySet, JWKSet $signatureKeySet, ?int &$signature = null): JWS
    {
        $recipient = null;
        $jwe = $this->jweLoader->loadAndDecryptWithKeySet($token, $encryptionKeySet, $recipient);
        $this->checkContentTypeHeader($jwe, $recipient);
        if (null === $jwe->getPayload()) {
            throw new \InvalidArgumentException('The token has no payload.');
        }

        return $this->jwsLoader->loadAndVerifyWithKeySet($jwe->getPayload(), $signatureKeySet, $signature);
    }
1331375
public static function getAsset($token)
    {
        $key = self::getJwtKey();

        $payload = JWT::decode($token, $key, array('HS256'));

        $providerClass = $payload->provider;
        $category = $payload->category;
        $data = (array) $payload->data;

        $provider = new $providerClass($category);

        return new Asset($token, $provider, $data);
    }
1038801
private function jwt()
    {
        if (!$this->jwt) {
            if (!$this->accessToken) {
                throw new EndpointException("No access token was provided");
            }

            $this->jwt = (new Parser())->parse($this->accessToken);
            $this->checkSignature();
        }
    }
1126704
public function authenticate($token, $authMethod = null)
    {
        if ($token === null) {
            throw InvalidArgumentException('You need to specify a token');
        }

        if ($authMethod === null) {
            $authMethod = self::AUTH_URL_TOKEN;
        }

        $this->getHttpClient()->authenticate($token, $authMethod);
    }
168288
public function createToken($input)
    {
        $i = 0;
        $token = $this->readAlternativeSentenceOrSingle($input, $i);

        if (isset($input[$i])) {
            throw new \InvalidArgumentException('Invalid root token, expression has superfluous contents');
        }

        return $token;
    }
376877
public function start(Request $request, AuthenticationException $authException = null)
    {
        $exception = new MissingTokenException('JWT Token not found', 0, $authException);
        $event     = new JWTNotFoundEvent($exception, new JWTAuthenticationFailureResponse($exception->getMessageKey()));

        if ($this->dispatcher instanceof ContractsEventDispatcherInterface) {
            $this->dispatcher->dispatch($event, Events::JWT_NOT_FOUND);
        } else {
            $this->dispatcher->dispatch(Events::JWT_NOT_FOUND, $event);
        }

        return $event->getResponse();
    }
579333
public function decode($jwt)
    {
        $wellKnown = $this->getWellKnown();
        $key = $this->getPublicKey();
        $decodedObject = JWT::decode(
            $jwt,
            $key,
            $wellKnown->id_token_signing_alg_values_supported
        );

        //Firebase\JWT\JWT::decode does not verify that some required
        //fields actually exist
        if (empty($decodedObject->iss)) {
            throw new NoIssuerException('No issuer in JWT');
        }
        if ($decodedObject->iss != $wellKnown->issuer) {
            throw new BadIssuerException('JWT issuer does not match well-known');
        }
        if (empty($decodedObject->exp)) {
            //Firebase\JWT\JWT does throw an exception if 'exp' field is in
            //the past, but not if it's completely missing
            throw new NoExpirationException('No expiration in JWT');
        }

        //JWT::decode returns at stdClass object, but iterating through keys is much
        //simpler with an array. So here's a quick Object-to-Array conversion
        $decoded = json_decode(json_encode($decodedObject), true);

        return $this->parseClaims($decoded);
    }
953570
public function getUserIdFromToken(string $token): string
    {
        if (!$this->isTokenValid($token)) {
            throw new \InvalidArgumentException('This token is invalid');
        }
        $tokenData = $this->decryptToken($token);

        return $tokenData['user_id'];
    }
1277640
public function setProjectToken($token)
    {
        if (!$token) {
            throw new InvalidArgumentException('Project token required');
        } elseif (strlen($token) !== 32) {
            throw new InvalidArgumentException('Project token must be 32 characters length');
        }

        $this->projectToken = $token;

        return $this;
    }
51391
public String generateJwt() throws NexmoUnacceptableAuthException {
        JWTAuthMethod authMethod = this.httpWrapper.getAuthCollection().getAuth(JWTAuthMethod.class);
        return authMethod.constructToken(System.currentTimeMillis() / 1000L, JWTAuthMethod.constructJTI());
    }
793476
public static function fromString(string $token): self
    {
        $instance = new self();
        $instance->token = $token;

        $parsed = explode('.', $token);
        if (count($parsed) !== 3) {
            throw new InvalidArgumentException('PbjxToken string is invalid.');
        }

        $instance->header = json_decode(self::urlsafeB64Decode($parsed[0]), true);
        $instance->payload = json_decode(self::urlsafeB64Decode($parsed[1]), true);
        $instance->signature = self::urlsafeB64Decode($parsed[2]);
        $instance->checkClaims();

        $instance->payload['exp'] = (int)$instance->payload['exp'];
        $instance->payload['iat'] = (int)$instance->payload['iat'];

        return $instance;
    }
471790
public function getDecodedToken(string $jwt)
    {
        try {
            /** @noinspection PhpUnusedLocalVariableInspection */
            [$headb64, $bodyb64, $cryptob64] = \explode('.', $jwt);
            $decodedToken = \json_decode(JWT::urlsafeB64Decode($bodyb64));

            /** @noinspection NullPointerExceptionInspection */
            JWT::decode($jwt, $this->findTenant($decodedToken->iss)->getSharedSecret(), ['HS256']);

            return $decodedToken;
        } catch (\Throwable $e) {
            throw new AuthenticationException($e->getMessage());
        }
    }