<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Validate a Facebook JavaScript SDK cookie with Ruby</title>
	<atom:link href="http://lostechies.com/joshuaflanagan/2010/11/17/validate-a-facebook-javascript-sdk-cookie-with-ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/joshuaflanagan/2010/11/17/validate-a-facebook-javascript-sdk-cookie-with-ruby/</link>
	<description></description>
	<lastBuildDate>Thu, 14 Mar 2013 03:50:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
	<item>
		<title>By: Shogo</title>
		<link>http://lostechies.com/joshuaflanagan/2010/11/17/validate-a-facebook-javascript-sdk-cookie-with-ruby/#comment-283</link>
		<dc:creator>Shogo</dc:creator>
		<pubDate>Sun, 26 Aug 2012 17:54:00 +0000</pubDate>
		<guid isPermaLink="false">/blogs/joshuaflanagan/archive/2010/11/16/validate-a-facebook-javascript-sdk-cookie-with-ruby.aspx#comment-283</guid>
		<description>Thanks Joshua! Its working great! </description>
		<content:encoded><![CDATA[<p>Thanks Joshua! Its working great! </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://lostechies.com/joshuaflanagan/2010/11/17/validate-a-facebook-javascript-sdk-cookie-with-ruby/#comment-282</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Sat, 25 Aug 2012 14:40:00 +0000</pubDate>
		<guid isPermaLink="false">/blogs/joshuaflanagan/archive/2010/11/16/validate-a-facebook-javascript-sdk-cookie-with-ruby.aspx#comment-282</guid>
		<description>I did not update to use a 3rd party SDK. I only needed to make a few changes to my code:

cookie = request.cookies[&quot;fbsr_#{@fb_app_id}&quot;]

fb_info = JSON.parse(urldecode64(cookie.split(&#039;.&#039;,2)[1]))

def urldecode64(str)
  encoded_str = str.tr(&#039;-_&#039;, &#039;+/&#039;)
  encoded_str += &#039;=&#039; while !(encoded_str.size % 4).zero?
  Base64.decode64(encoded_str)
end

def valid_cookie?
  return false unless cookie
  return false if fb_info[&#039;algorithm&#039;].to_s.upcase != &#039;HMAC-SHA256&#039;
  encoded_sig, payload = cookie.split(&#039;.&#039;, 2)
  sig = urldecode64(encoded_sig)
  expected_sig = OpenSSL::HMAC.digest(&#039;sha256&#039;, settings.fb_app_secret, payload)
  expected_sig == sig
end</description>
		<content:encoded><![CDATA[<p>I did not update to use a 3rd party SDK. I only needed to make a few changes to my code:</p>
<p>cookie = request.cookies["fbsr_#{@fb_app_id}"]</p>
<p>fb_info = JSON.parse(urldecode64(cookie.split(&#8216;.&#8217;,2)[1]))</p>
<p>def urldecode64(str)<br />
  encoded_str = str.tr(&#8216;-_&#8217;, &#8216;+/&#8217;)<br />
  encoded_str += &#8216;=&#8217; while !(encoded_str.size % 4).zero?<br />
  Base64.decode64(encoded_str)<br />
end</p>
<p>def valid_cookie?<br />
  return false unless cookie<br />
  return false if fb_info['algorithm'].to_s.upcase != &#8216;HMAC-SHA256&#8242;<br />
  encoded_sig, payload = cookie.split(&#8216;.&#8217;, 2)<br />
  sig = urldecode64(encoded_sig)<br />
  expected_sig = OpenSSL::HMAC.digest(&#8216;sha256&#8242;, settings.fb_app_secret, payload)<br />
  expected_sig == sig<br />
end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shogo</title>
		<link>http://lostechies.com/joshuaflanagan/2010/11/17/validate-a-facebook-javascript-sdk-cookie-with-ruby/#comment-281</link>
		<dc:creator>Shogo</dc:creator>
		<pubDate>Sat, 25 Aug 2012 08:06:00 +0000</pubDate>
		<guid isPermaLink="false">/blogs/joshuaflanagan/archive/2010/11/16/validate-a-facebook-javascript-sdk-cookie-with-ruby.aspx#comment-281</guid>
		<description>for the mean time, Andrew from the #facebook chatroom on irc.freenode.net advised me to look at the PHP opensource code to see how they do it.  This code looks like a good place to start:  https://github.com/facebook/facebook-php-sdk/blob/master/src/base_facebook.php#L987</description>
		<content:encoded><![CDATA[<p>for the mean time, Andrew from the #facebook chatroom on irc.freenode.net advised me to look at the PHP opensource code to see how they do it.  This code looks like a good place to start:  https://github.com/facebook/facebook-php-sdk/blob/master/src/base_facebook.php#L987</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shogo</title>
		<link>http://lostechies.com/joshuaflanagan/2010/11/17/validate-a-facebook-javascript-sdk-cookie-with-ruby/#comment-280</link>
		<dc:creator>Shogo</dc:creator>
		<pubDate>Sat, 25 Aug 2012 06:20:00 +0000</pubDate>
		<guid isPermaLink="false">/blogs/joshuaflanagan/archive/2010/11/16/validate-a-facebook-javascript-sdk-cookie-with-ruby.aspx#comment-280</guid>
		<description>Thanks for the warning Joshua.  Are you planning to move to one of the various 3rd party ruby sdks listed on:  https://developers.facebook.com/tools/third-party-sdks/#ruby

I&#039;m not sure if any of them satisfy:
 1. Sinatra
 2. Integration with the Facebook SDK for Javascript</description>
		<content:encoded><![CDATA[<p>Thanks for the warning Joshua.  Are you planning to move to one of the various 3rd party ruby sdks listed on:  https://developers.facebook.com/tools/third-party-sdks/#ruby</p>
<p>I&#8217;m not sure if any of them satisfy:<br />
 1. Sinatra<br />
 2. Integration with the Facebook SDK for Javascript</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://lostechies.com/joshuaflanagan/2010/11/17/validate-a-facebook-javascript-sdk-cookie-with-ruby/#comment-279</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Fri, 24 Aug 2012 13:11:00 +0000</pubDate>
		<guid isPermaLink="false">/blogs/joshuaflanagan/archive/2010/11/16/validate-a-facebook-javascript-sdk-cookie-with-ruby.aspx#comment-279</guid>
		<description>This article is now out of date. I discovered the same problem recently. The cookie now comes through as &quot;fbsr_#{@fb_app_id:disqus }&quot;, and I think it is intended to be used in a different way. See some discussion here: http://stackoverflow.com/questions/7206204/new-js-sdk-with-oauth-2-0-saving-subdomain-in-fbsr-cookie

I will update this article with a warning.</description>
		<content:encoded><![CDATA[<p>This article is now out of date. I discovered the same problem recently. The cookie now comes through as &#8220;fbsr_#{@fb_app_id:disqus }&#8221;, and I think it is intended to be used in a different way. See some discussion here: http://stackoverflow.com/questions/7206204/new-js-sdk-with-oauth-2-0-saving-subdomain-in-fbsr-cookie</p>
<p>I will update this article with a warning.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shogo</title>
		<link>http://lostechies.com/joshuaflanagan/2010/11/17/validate-a-facebook-javascript-sdk-cookie-with-ruby/#comment-278</link>
		<dc:creator>Shogo</dc:creator>
		<pubDate>Fri, 24 Aug 2012 09:24:00 +0000</pubDate>
		<guid isPermaLink="false">/blogs/joshuaflanagan/archive/2010/11/16/validate-a-facebook-javascript-sdk-cookie-with-ruby.aspx#comment-278</guid>
		<description>cookie = request.cookies[&quot;fbs_#{@fb_app_id}&quot;]
on the sinatra server side, my cookie is nil. I am logged in with the javascript sdk with status and cookie set to true for FB.init
i even hardcoded fbs_123456 #thats not my real app id of course.
I found your article because 3rd party tools like fb_graph are not working with the javascript sdk (or I can&#039;t get it to work).</description>
		<content:encoded><![CDATA[<p>cookie = request.cookies["fbs_#{@fb_app_id}"]<br />
on the sinatra server side, my cookie is nil. I am logged in with the javascript sdk with status and cookie set to true for FB.init<br />
i even hardcoded fbs_123456 #thats not my real app id of course.<br />
I found your article because 3rd party tools like fb_graph are not working with the javascript sdk (or I can&#8217;t get it to work).</p>
]]></content:encoded>
	</item>
</channel>
</rss>
