Skip to content
This repository has been archived by the owner on Dec 30, 2020. It is now read-only.

Commit

Permalink
Custom http headers (#323)
Browse files Browse the repository at this point in the history
* Custom header Support
  • Loading branch information
Spomky authored May 3, 2018
1 parent 7f34e21 commit c783529
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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.",
Expand All @@ -48,7 +48,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "7.0.x-dev"
"dev-master": "7.1.x-dev"
}
}
}
1 change: 0 additions & 1 deletion examples/NestedTokens1.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,3 @@
'zip' => 'DEF',
]
);
var_dump($jwe);
8 changes: 4 additions & 4 deletions src/Factory/JWKFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/Factory/JWKFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,23 @@ 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
* @param bool $allow_unsecured_connection
* @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
Expand Down
12 changes: 11 additions & 1 deletion src/Object/DownloadedJWKSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ abstract class DownloadedJWKSet extends BaseJWKSet implements JWKSetInterface
*/
private $allow_unsecured_connection;

/**
* @var array
*/
private $custom_headers = [];

/**
* DownloadedJWKSet constructor.
*
Expand All @@ -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);
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit c783529

Please sign in to comment.