Decoding Facebook's signed request in Ruby/Sinatra Decoding Facebook's signed request in Ruby/Sinatra json json

Decoding Facebook's signed request in Ruby/Sinatra


I've run into this before. You just need to pad the end of the payload string with = marks until its length is divisible by 4.

This will work:

payload += '=' * (4 - payload.length.modulo(4))

(I'm not sure where/if this is documented by Facebook, but someone on IRC told me about it in early 2011, and sure enough, I've since found such padding in the source code of various Facebook client libraries)


The answer from dorkitude was correct. I just had the same issue and padding it with a "=" worked.

You can verify this by using:

Base64.strict_decode64( invalid_payload )=> ArgumentError: invalid base64