Decoding Facebook's signed request in Ruby/Sinatra

对着背影说爱祢 提交于 2019-12-03 02:41:37

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)

I use fbgraph library which has working parse_signed_request method.

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!