Almost all Graph API libraries that are available deal with signed_request in a similar way. Rest-Graph has a parse_signed_request method ( Rest-Graph / lib / core.rb ) that you can call in Sinatra.
I use Koala for this with Sinatra and it works as advertised:
oauth = Koala::Facebook::OAuth.new(APP_ID, APP_CODE) signed_request = oauth.parse_signed_request(params["signed_request"])
You return the hash of the JSON object that Facebook publishes:
{ "algorithm"=>"HMAC-SHA256", "issued_at"=>1303883452, "user"=> { "country"=>"us", "locale"=>"en_US" }, "user_id"=>"100002364226618" }
rest-graph also makes it pretty simple. Just tested it in the Sinatra app. Works great:
rg = RestGraph.new( :app_id => APP_ID, :secret => APP_SECRET) parsed_request = rg.parse_signed_request!(params["signed_request"])
Lemme know this does not work for you.
source share