Reading facebook JSON object "signed_request"

I'm designing a Facebook canvas app, and am just at the beginning.  To test that I can communicate with Facebook correctly at all, I am trying to read the JSON object that Facebook sends to my page, named "signed_request".  Every method I try to use to read it claims that the base64 JSON object data is invalid.  For example, using the JSON.net library, in vb.net, with this code:
Dim mystring As String
mystring = JsonConvert.DeserializeObject(request.form("signed_request"))

I get this error:
Newtonsoft.Json.JsonReaderException: Error parsing boolean value. Line 1, position 2.

Or, when using built-in string conversion functions with this code:
Dim b As Byte() = Convert.FromBase64String(request.form("signed_request"))
mystring = System.Text.Encoding.UTF8.GetString(b)

I get:
System.FormatException: Invalid character in a Base-64 string.

What am I doing wrong?
CarbaseAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
If I understand what "signed_request" is, it is a Base-64 encoded URL.

You could use the HttpServerUtility.UrlTokenDecode method decode a Base-64 URL.

Code for decoding/encoding a modified base64 URL
http://stackoverflow.com/questions/1228701/code-for-decoding-encoding-a-modified-base64-url

''<summary>
''' Base 64 Encoding with URL and Filename Safe Alphabet using UTF-8 character set.
'''</summary>
'''<param name="str">The origianl string</param>
'''<returns>The Base64 encoded string</returns>
Public Shared Function Base64Encode(str As String) As String
	Dim encbuff As Byte() = Encoding.UTF8.GetBytes(str)
	Return HttpServerUtility.UrlTokenEncode(encbuff)
End Function

'''<summary>
''' Decode Base64 encoded string with URL and Filename Safe Alphabet using UTF-8.
'''</summary>
'''<param name="str">Base64 code</param>
'''<returns>The decoded string.</returns>
Public Shared Function Base64Decode(str As String) As String
	Dim decbuff As Byte() = HttpServerUtility.UrlTokenDecode(str)
	Return Encoding.UTF8.GetString(decbuff)
End Function

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CarbaseAuthor Commented:
It is mostly a Base-64 encoded URL, but I found out they prepended some other info to it, separating the two sections with a dot.  Once I looked just after the dots, and padded the length when necessary, everything was fine.

Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.