Skip to content

Commit

Permalink
Merge pull request #41 from n-s-f/master
Browse files Browse the repository at this point in the history
do not escape slashes in json_encoding of jwt components
  • Loading branch information
odino committed Jul 29, 2015
2 parents d0fc315 + 6ce1426 commit 0b3af07
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Namshi/JOSE/JWT.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public function setEncoder(Encoder $encoder)
*/
public function generateSigninInput()
{
$base64payload = $this->encoder->encode(json_encode($this->getPayload()));
$base64header = $this->encoder->encode(json_encode($this->getHeader()));
$base64payload = $this->encoder->encode(json_encode($this->getPayload(), JSON_UNESCAPED_SLASHES));
$base64header = $this->encoder->encode(json_encode($this->getHeader(), JSON_UNESCAPED_SLASHES));

return sprintf("%s.%s", $base64header, $base64payload);
}
Expand Down
10 changes: 10 additions & 0 deletions tests/Namshi/JOSE/Test/JWTTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ public function testGenerationOfTheSigninInput()
$this->assertEquals(sprintf("%s.%s", $encoder->encode(json_encode($header)), $encoder->encode(json_encode($payload))), $jwt->generateSigninInput());
}

public function testGenerationOfTheSigninInputCanHandleSlashes()
{
$encoder = new Base64UrlSafeEncoder();
$json_string = '{"a":"/b/"}';
$encoded_json_string = $encoder->encode($json_string);
$jwt = new JWT(json_decode($json_string, true), json_decode($json_string, true));

$this->assertEquals(sprintf("%s.%s", $encoded_json_string, $encoded_json_string), $jwt->generateSigninInput());
}

public function testPayload()
{
$jwt = new JWT(array('a' => 'b'), array());
Expand Down

0 comments on commit 0b3af07

Please sign in to comment.