Skip to content

Commit 25253be

Browse files
committed
Adding header options to add
1 parent 30a0668 commit 25253be

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Authentication/JWT.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,21 @@ public static function decode($jwt, $key = null, $allowed_algs = array())
119119
* @param string $key The secret key
120120
* @param string $alg The signing algorithm. Supported
121121
* algorithms are 'HS256', 'HS384' and 'HS512'
122+
* @param array $head An array with header elements to attach
122123
*
123124
* @return string A signed JWT
124125
* @uses jsonEncode
125126
* @uses urlsafeB64Encode
126127
*/
127-
public static function encode($payload, $key, $alg = 'HS256', $keyId = null)
128+
public static function encode($payload, $key, $alg = 'HS256', $keyId = null, $head = null)
128129
{
129130
$header = array('typ' => 'JWT', 'alg' => $alg);
130131
if ($keyId !== null) {
131132
$header['kid'] = $keyId;
132133
}
134+
if ( isset($head) && is_array($head) ) {
135+
array_push($header, $head);
136+
}
133137
$segments = array();
134138
$segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($header));
135139
$segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($payload));

0 commit comments

Comments
 (0)