Specifically I'm trying to decode the signed_request that Facebook
returns from its Registration plugin. Splitting it into its two parts
and running debase64() on the second part works, though the resulting
string ends up with an extra quote mark. The result looks like JSON
but the parseJSON() method always returns false. It's definitely a
string, it looks well-formed, but it won't parse. Any ideas? Facebook
uses Base64Url encoding, might that gave something to do with it?
Notice there's substantial whitespace before and after the string. And
I redacted my Facebook ID.
Minus the whitespace and the last quote mark this passes the JSON
parser at http://json.parser.online.fr/ I thought unwrap() would remove the newlines in this chunk of text but
it doesn't seem to do much. Curious.
Thanks Simon.
On Mar 25, 3:13 am, Simon Oberhammer <simon.oberham...@gmail.com>
wrote:
are you sure you aren't cutting the json in half when you do the split()? maybe facebooks does base64(JSON.stringify(obj)). thus if you first split, then debase64() and finally parse() you will end up with broken JSON.
i wouldn't do unwrap() - linebreaks are fine in json.
Facebook returns a Base64Url string in two parts separated by a
period, so I split on that, so that shouldn't be the problem. (The
first part is an encoded hash I think.) As I said the string above
comes out after the split().debase64() combo.
I found a jar that does Base64 and Base64u and I dropped that into my
installation and tried to patch modules/core/String.js with a new
method to use it, but I keep getting type errors when I try to invoke
the functions that are supposed to be exposed.
It's an interesting problem.
Thanks,
Pete
On Mar 25, 11:00 am, Simon Oberhammer <simon.oberham...@gmail.com>
wrote:
> are you sure you aren't cutting the json in half when you do the
> split()? maybe facebooks does base64(JSON.stringify(obj)). thus if you
> first split, then debase64() and finally parse() you will end up with
> broken JSON.
> i wouldn't do unwrap() - linebreaks are fine in json.
HA! Got it. It's definitely the Base64Url encoding. When I figured out
how to wrap a Java library that handled base64u, I patched the String
prototype with a new method and got the Facebook stuff decoded
correctly. parseJSON() now spits out a proper JSON object.