views:

13

answers:

0

Hello!

I am using Rails 3 and the Facebook Javascript SDK and when I login a cookie is created. I want to be able to extract data from this cookie using Rails.

I got a PHP code that does the trick but I want to use Rails code. What does the below code written in PHP look like in Rails?

function get_facebook_cookie($app_id, $application_secret) {
  $args = array();
  parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
  ksort($args);
  $payload = '';
  foreach ($args as $key => $value) {
    if ($key != 'sig') {
      $payload .= $key . '=' . $value;
    }
  }
  if (md5($payload . $application_secret) != $args['sig']) {
    return null;
  }
  return $args;
}

$cookie = get_facebook_cookie(FACEBOOK_APP_ID, FACEBOOK_SECRET);

Please help!