0
votes

So I've been fiddling about with creating a Facebook Page App and am running into an obstacle.

The API Documentation (https://developers.facebook.com/docs/reference/login/signed-request/) indicates that it is a json encoded base64 encoded string, but I've found that more often then not it doesn't decode (PHP) properly.

Example String

[signed_request] => ccskn7MGtWvG9XXAU5F8nE61aFy-PP-2Jmvz35iwtOo.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImlzc3VlZF9hdCI6MTM4NjEyNTk5NCwicGFnZSI6eyJpZCI6IjM5ODYxMDQ0MDIxNDI2NiIsImxpa2VkIjpmYWxzZSwiYWRtaW4iOnRydWV9LCJ1c2VyIjp7ImNvdW50cnkiOiJ1cyIsImxvY2FsZSI6ImVuX1VTIiwiYWdlIjp7Im1pbiI6MjF9fX0

I did find this other question (Invalid base64 in Facebook signed_request documentation example), but after trying to add padding, still not gibberish results.

Any help is appreciated.

1
Have you replaced the characters - and _ by + and / respectively before trying to base64 decode it …? - CBroe
I have, but unfortunately it doesn't change anything. - Lorenzo Aiello
The example signed request that you posted decodes perfectly fine. - CBroe
Whaa? I get q$kuS|Nh\?bf=N쉅ɥѡ!5M!؈Օ}Ја쉥؈际͔Օ͕Ȉ쉍չ̈艕}UL쉵 when I used base64_decode() - can you please share code? - Lorenzo Aiello
Have you maybe forgotten to split the whole thing at the first dot, and only decode the second part? - CBroe

1 Answers

1
votes

To parse the signed_request, first it must be split at the first dot . character, and then in the second part you have to replace the characters - and _ by + and / respectively – and after that base64-decode it.

As for your question, where this is documented – in the document that is linked right on top of the document that you mentioned, here: https://developers.facebook.com/docs/facebook-login/using-login-with-games/#parsingsr