Created
March 24, 2011 02:48
-
-
Save mexitek/884450 to your computer and use it in GitHub Desktop.
How to handle facebook's signed_request FORM Parameter in Coldfusion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- Check for the param ---> | |
<cfparam name="FORM.signed_request" default=""> | |
<!--- Split the param by the . ---> | |
<cfset raw_str = ListGetAt(FORM.signed_request, 2, ".")> | |
<!--- Add padding if string is too short. ---> | |
<!--- CF Fix: Exception invalid base64 string ---> | |
<cfset res = Len(raw_str) % 4> | |
<cfif res eq 2> | |
<cfset raw_str &= "=="> | |
<cfelseif res eq 3> | |
<cfset raw_str &= "="> | |
</cfif> | |
<!--- Base 64 Decode ---> | |
<cfset result = ToString(BinaryDecode(raw_str, "Base64"))> | |
<!--- String to JSON ---> | |
<cfset json = DeserializeJSON(result)> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- Check for the param ---> | |
<cfparam name="FORM.signed_request" default=""> | |
<!--- Split the param by the . ---> | |
<cfset raw_str = ListGetAt(FORM.signed_request, 2, ".")> | |
<!--- Add padding if string is too short. ---> | |
<!--- CF Fix: Exception invalid base64 string ---> | |
<cfset res = Len(raw_str) % 4> | |
<cfif res eq 2> | |
<cfset raw_str &= "=="> | |
<cfelseif res eq 3> | |
<cfset raw_str &= "="> | |
</cfif> | |
<!--- Base 64 Decode ---> | |
<cfset result = ToString(BinaryDecode(raw_str, "Base64"))> | |
<!--- String to JSON ---> | |
<cfset json = DeserializeJSON(result)> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment