Created
June 4, 2011 19:21
-
-
Save joshellington/1008237 to your computer and use it in GitHub Desktop.
Facebook iframe signed request
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
require 'json' | |
require 'base64' | |
# Decoding functions | |
def base64_url_decode str | |
encoded_str = str.gsub('-','+').gsub('_','/') | |
encoded_str += '=' while !(encoded_str.size % 4).zero? | |
Base64.decode64(encoded_str) | |
end | |
def decode_data(signed_request) | |
encoded_sig, payload = signed_request.split('.') | |
data = base64_url_decode(payload) | |
end | |
# Parsing in your route | |
post '/route?' do | |
@encoded_request = params[:signed_request] | |
@json_request = decode_data(@encoded_request) | |
@signed_request = JSON.parse(@json_request) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment