Jose\JWTLoader::load PHP Method

load() public method

public load ( $assertion, Jose\Object\JWKSetInterface $encryption_key_set = null, $is_encryption_required = false )
$encryption_key_set Jose\Object\JWKSetInterface
    public function load($assertion, Object\JWKSetInterface $encryption_key_set = null, $is_encryption_required = false)
    {
        Assertion::string($assertion);
        Assertion::boolean($is_encryption_required);
        $jwt = $this->loader->load($assertion);
        if ($jwt instanceof Object\JWEInterface) {
            Assertion::notNull($encryption_key_set, 'Encryption key set is not available.');
            Assertion::true($this->isDecryptionSupportEnabled(), 'Encryption support is not enabled.');
            Assertion::inArray($jwt->getSharedProtectedHeader('alg'), $this->getSupportedKeyEncryptionAlgorithms(), sprintf('The key encryption algorithm "%s" is not allowed.', $jwt->getSharedProtectedHeader('alg')));
            Assertion::inArray($jwt->getSharedProtectedHeader('enc'), $this->getSupportedContentEncryptionAlgorithms(), sprintf('The content encryption algorithm "%s" is not allowed or not supported.', $jwt->getSharedProtectedHeader('enc')));
            $jwt = $this->decryptAssertion($jwt, $encryption_key_set);
        } elseif (true === $is_encryption_required) {
            throw new \InvalidArgumentException('The assertion must be encrypted.');
        }
        return $jwt;
    }

Usage Example

 /**
  * {@inheritdoc}
  */
 public function decode($token)
 {
     try {
         $jws = $this->jwt_loader->load($token, $this->encryption_jwkset, null !== $this->encryption_jwkset);
         $this->jwt_loader->verify($jws, $this->signature_jwkset);
         return $jws->getClaims();
     } catch (\Exception $e) {
         $reason = $this->getDecodeErrorReason($e->getMessage());
         throw new JWTDecodeFailureException($reason, sprintf('Invalid JWT Token: %s', $e->getMessage()), $e);
     }
 }