2

When facebook loads my app into the iframe I get in the POST data the signed_request parameter, I then take the part after the "." and decode that with base64 to get the json string representation of the signed request.

For some reason the json string that is decoded from the signed request is incomplete and looks like this (formatted for easy reading):

{
    "algorithm": "HMAC-SHA256",
    "expires": xxxxxxxxxxx,
    "issued_at": xxxxxxxxxx,
    "oauth_token": "xxxxxxxxxxxxxxxxxxxxxxxx",
    "user": {
        "country": "il",
        "locale": "en_US",
        "age": {
            "min": 21
        }
    },
    "user_id":"xxxxxxxxx

The user_id is correct and complete but then the rest of the string is missing the closing double quote and the closing bracket. This happens to me every time now with my app, it's on sandbox mode.

Any ideas of why this happens? Thanks.


Edit

I checked that it's not some decoding error in my program, I copied the content that is being posted and checked it in an online decoder and got the exact same result.

2
  • Hi, Since you were able to decode the signed_request, can you please suggest me how to do that. I am unable to do it, here is my question stackoverflow.com/questions/9917547/… Commented Mar 29, 2012 at 0:31
  • I have this exact same problem in my production environment (non-sandbox mode) but not in the dev environment (sandbox mode), very strange...please update if you have any solution! Commented Mar 31, 2012 at 21:38

2 Answers 2

1

I solved this same problem by updating to commons codec 1.6

Sign up to request clarification or add additional context in comments.

4 Comments

What? are you saying that it's a problem with the decoder I'm using? But the online decoder I tested with gave the same exact result, are they using a faulted decoder too? (I will test what you are saying but it will take some time to have my environment ready for that)
I ran into the same problem, easy for me to update the commons codec library, but you could just add the characters manually. Have a look here qugstart.com/blog/ruby-and-rails/…
Thanks for the info. I haven't actually tested what you're saying (with the codec 1.6) and it will take a bit of time until I will be able to. Adding the missing chars is what I did, but it's hardly a solution, more like a workaround.
Just wanted to verify that replacing the commons codec to the new version (1.6) did fix the problem. Thanks.
1

This worked for me (trimming the String and adding a trailing bracket):

String jsonString = new String(Base64.decodeBase64(payload.getBytes())).trim(); jsonString = jsonString + "}";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.