Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding optional headers to send in JWT #53

merged 6 commits into from Jun 22, 2015
Changes from all commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.


Just for now

@@ -119,17 +119,21 @@ public static function decode($jwt, $key = null, $allowed_algs = array())
* @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) ) {
$header = array_merge($head, $header);
$segments = array();
$segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($header));
$segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($payload));
@@ -228,4 +228,10 @@ public function testMissingAlgorithm()
JWT::decode($msg, 'my_key');

public function testAdditionalHeaders()
$msg = JWT::encode('abc', 'my_key', 'HS256', null, array('cty' => 'test-eit;v=1'));
$this->assertEquals(JWT::decode($msg, 'my_key', array('HS256')), 'abc');
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.