From c7835297fa6a2c00dcdcbfadd67f7ea099b226a1 Mon Sep 17 00:00:00 2001 From: Spomky Date: Thu, 3 May 2018 09:34:56 +0200 Subject: [PATCH] Custom http headers (#323) * Custom header Support --- composer.json | 8 ++++---- examples/NestedTokens1.php | 1 - src/Factory/JWKFactory.php | 8 ++++---- src/Factory/JWKFactoryInterface.php | 6 ++++-- src/Object/DownloadedJWKSet.php | 12 +++++++++++- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index 403db5b1..db09b373 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "php": "^7.0", "lib-openssl": "*", "spomky-labs/base64url": "^1.0", - "spomky-labs/aes-key-wrap": "^3.0", + "spomky-labs/aes-key-wrap": "^3.0|^4.0", "spomky-labs/php-aes-gcm": "^1.2", "beberlei/assert": "^2.4", "symfony/polyfill-mbstring": "^1.1", @@ -38,8 +38,8 @@ }, "require-dev": { "phpunit/phpunit": "^6.0", - "satooshi/php-coveralls": "^1.0", - "symfony/cache": "^2.0|^3.0" + "satooshi/php-coveralls": "^2.0", + "symfony/cache": "^2.0|^3.0|^4.0" }, "suggest":{ "ext-crypto": "Highly recommended when you use AES GCM based algorithms.", @@ -48,7 +48,7 @@ }, "extra": { "branch-alias": { - "dev-master": "7.0.x-dev" + "dev-master": "7.1.x-dev" } } } diff --git a/examples/NestedTokens1.php b/examples/NestedTokens1.php index ea031bcf..a1e6b261 100644 --- a/examples/NestedTokens1.php +++ b/examples/NestedTokens1.php @@ -51,4 +51,3 @@ 'zip' => 'DEF', ] ); -var_dump($jwe); diff --git a/src/Factory/JWKFactory.php b/src/Factory/JWKFactory.php index bd49aa1a..2f119d04 100644 --- a/src/Factory/JWKFactory.php +++ b/src/Factory/JWKFactory.php @@ -366,17 +366,17 @@ public static function createFromKey($key, $password = null, array $additional_v /** * {@inheritdoc} */ - public static function createFromJKU($jku, $allow_unsecured_connection = false, CacheItemPoolInterface $cache = null, $ttl = 86400, $allow_http_connection = false) + public static function createFromJKU($jku, $allow_unsecured_connection = false, CacheItemPoolInterface $cache = null, $ttl = 86400, $allow_http_connection = false, array $custom_headers = []) { - return new JKUJWKSet($jku, $cache, $ttl, $allow_unsecured_connection, $allow_http_connection); + return new JKUJWKSet($jku, $cache, $ttl, $allow_unsecured_connection, $allow_http_connection, $custom_headers); } /** * {@inheritdoc} */ - public static function createFromX5U($x5u, $allow_unsecured_connection = false, CacheItemPoolInterface $cache = null, $ttl = 86400, $allow_http_connection = false) + public static function createFromX5U($x5u, $allow_unsecured_connection = false, CacheItemPoolInterface $cache = null, $ttl = 86400, $allow_http_connection = false, array $custom_headers = []) { - return new X5UJWKSet($x5u, $cache, $ttl, $allow_unsecured_connection, $allow_http_connection); + return new X5UJWKSet($x5u, $cache, $ttl, $allow_unsecured_connection, $allow_http_connection, $custom_headers); } /** diff --git a/src/Factory/JWKFactoryInterface.php b/src/Factory/JWKFactoryInterface.php index 6aae4da2..349ced91 100644 --- a/src/Factory/JWKFactoryInterface.php +++ b/src/Factory/JWKFactoryInterface.php @@ -154,10 +154,11 @@ public static function createFromKey($key, $password = null, array $additional_v * @param \Psr\Cache\CacheItemPoolInterface|null $cache * @param int|null $ttl * @param bool $allow_http_connection + * @param array $custom_headers * * @return \Jose\Object\JWKSetInterface */ - public static function createFromJKU($jku, $allow_unsecured_connection = false, CacheItemPoolInterface $cache = null, $ttl = 86400, $allow_http_connection = false); + public static function createFromJKU($jku, $allow_unsecured_connection = false, CacheItemPoolInterface $cache = null, $ttl = 86400, $allow_http_connection = false, array $custom_headers = []); /** * @param string $x5u @@ -165,10 +166,11 @@ public static function createFromJKU($jku, $allow_unsecured_connection = false, * @param \Psr\Cache\CacheItemPoolInterface|null $cache * @param int|null $ttl * @param bool $allow_http_connection + * @param array $custom_headers * * @return \Jose\Object\JWKSetInterface */ - public static function createFromX5U($x5u, $allow_unsecured_connection = false, CacheItemPoolInterface $cache = null, $ttl = 86400, $allow_http_connection = false); + public static function createFromX5U($x5u, $allow_unsecured_connection = false, CacheItemPoolInterface $cache = null, $ttl = 86400, $allow_http_connection = false, array $custom_headers = []); /** * @param array $x5c diff --git a/src/Object/DownloadedJWKSet.php b/src/Object/DownloadedJWKSet.php index 180c3d53..ac72be54 100644 --- a/src/Object/DownloadedJWKSet.php +++ b/src/Object/DownloadedJWKSet.php @@ -41,6 +41,11 @@ abstract class DownloadedJWKSet extends BaseJWKSet implements JWKSetInterface */ private $allow_unsecured_connection; + /** + * @var array + */ + private $custom_headers = []; + /** * DownloadedJWKSet constructor. * @@ -49,8 +54,9 @@ abstract class DownloadedJWKSet extends BaseJWKSet implements JWKSetInterface * @param int $ttl * @param bool $allow_unsecured_connection * @param bool $allow_http_connection + * @param array $cache */ - public function __construct($url, CacheItemPoolInterface $cache = null, $ttl = 86400, $allow_unsecured_connection = false, $allow_http_connection = false) + public function __construct($url, CacheItemPoolInterface $cache = null, $ttl = 86400, $allow_unsecured_connection = false, $allow_http_connection = false, array $custom_headers = []) { Assertion::boolean($allow_unsecured_connection); Assertion::boolean($allow_http_connection); @@ -67,6 +73,7 @@ public function __construct($url, CacheItemPoolInterface $cache = null, $ttl = 8 $this->cache = $cache; $this->ttl = $ttl; $this->allow_unsecured_connection = $allow_unsecured_connection; + $this->custom_headers = $custom_headers; } /** @@ -139,6 +146,9 @@ private function downloadContent() $ch = curl_init(); curl_setopt_array($ch, $params); + if (!empty($this->custom_headers)) { + curl_setopt($ch, CURLOPT_HTTPHEADER, $this->custom_headers); + } $content = curl_exec($ch); try {