psecio / jwt

A JWT (JSON Web Token) Encoder & Decoder
110 stars 13 forks source link

Does not work with JWT encoded with other tools because of escaping slashes #11

Closed Schnueggel closed 10 years ago

Schnueggel commented 10 years ago

PHP json_encode by default escapes slashes, which will break the verify when the token was generated with a other tool than psecio/jwt.

Perhaps ist would be good to at least make it possible to set the encoding and decoding options.

enygma commented 10 years ago

Can you give me an example of another tool to try with so I can verify it cooperates?

Schnueggel commented 10 years ago

For example this: http://federation-lab.uninett.no/jwt

enygma commented 10 years ago

Interesting...I wonder what the difference is between that and these others (works on them):

Schnueggel commented 10 years ago

Thats what I did and tested: I encode the following json with http://federation-lab.uninett.no/jwt

{
    "iss": "https://issuer.example.org",
    "exp": 1416057272,
    "http://example.com/is_root": true,
    "aud": "https://example.org"
}

The Result is this Token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL2lzc3Vlci5leGFtcGxlLm9yZyIsImV4cCI6MTQxNjA1NzI3MiwiaHR0cDovL2V4YW1wbGUuY29tL2lzX3Jvb3QiOnRydWUsImF1ZCI6Imh0dHBzOi8vZXhhbXBsZS5vcmciLCJ0eXAiOiJKV1QifQ.gNNDnZcAS9AAZ-l2Dbz7gKcxyGhILdNbwcSQsagF6BM

Then in Jwt.php on line 144 the claims get correctly decoded:

$this->base64Decode($claims)

Resulting in the same json as above.

Then in the verify method on line 247:

$this->base64Encode(json_encode($claims))

json_encode($claims) results in:

{"iss":"https:\/\/issuer.example.org","exp":1416057272,"http:\/\/example.com\/is_root":true,"aud":"https:\/\/example.org","typ":"JWT"}

Which will base64 encoded result in a different token and does not verify of course.

enygma commented 10 years ago

Okay, I just released 1.4 - give that a shot. Looks like it works here but I wanted to be sure.

Schnueggel commented 10 years ago

Yes works for me now. Thanks.

enygma commented 10 years ago

Excellent - thanks!