summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Cocaro <martin.cocaro@gmail.com>2015-06-17 14:21:04 -0700
committerMartin Cocaro <martin.cocaro@gmail.com>2015-06-17 14:21:04 -0700
commit25253be6872358440522702a1fe45c3ac4b653c6 (patch)
tree3f55a9bdac9072be6094c22ff34084d5e563e4e9
parent30a066878c44ad9676f87edf373cc7b74f0192b7 (diff)
downloadphp-jwt-25253be6872358440522702a1fe45c3ac4b653c6.zip
php-jwt-25253be6872358440522702a1fe45c3ac4b653c6.tar.gz
php-jwt-25253be6872358440522702a1fe45c3ac4b653c6.tar.bz2
Adding header options to add
-rw-r--r--Authentication/JWT.php6
1 files changed, 5 insertions, 1 deletions
diff --git a/Authentication/JWT.php b/Authentication/JWT.php
index 7d6665b..9c37539 100644
--- a/Authentication/JWT.php
+++ b/Authentication/JWT.php
@@ -119,17 +119,21 @@ class JWT
* @param string $key The secret key
* @param string $alg The signing algorithm. Supported
* algorithms are 'HS256', 'HS384' and 'HS512'
+ * @param array $head An array with header elements to attach
*
* @return string A signed JWT
* @uses jsonEncode
* @uses urlsafeB64Encode
*/
- public static function encode($payload, $key, $alg = 'HS256', $keyId = null)
+ public static function encode($payload, $key, $alg = 'HS256', $keyId = null, $head = null)
{
$header = array('typ' => 'JWT', 'alg' => $alg);
if ($keyId !== null) {
$header['kid'] = $keyId;
}
+ if ( isset($head) && is_array($head) ) {
+ array_push($header, $head);
+ }
$segments = array();
$segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($header));
$segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($payload));