Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mexitek/884450 to your computer and use it in GitHub Desktop.
Save mexitek/884450 to your computer and use it in GitHub Desktop.
How to handle facebook's signed_request FORM Parameter in Coldfusion
<!--- 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)>
<!--- 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