Sha256: 7e7dbafbde7fa9d46eb2770afe3d16e957734768261c0b6e368f3260e41a1bde

Contents?: true

Size: 661 Bytes

Versions: 1

Compression:

Stored size: 661 Bytes

Contents

require 'digest/md5'

class FacebookSigValidator
  # If the cookie is valid, return true.  If the cookie is out of date or invalid, return false.
  # cookies is a hash
  # app_id is your facebook app id
  # secret is your facebook app secret
  def self.valid_cookie?(cookies, app_id, secret)
    cookie = cookies["fbs_#{app_id}"].gsub(/\"/, "") rescue ''
    pairs = Hash[cookie.split("&").map {|kv| kv.split("=") }]
    str = pairs.keys.sort.collect {|a| a == "sig" ? nil : "#{a}=#{pairs[a]}"}.reject {|a| a.nil?}.join("")
    (Digest::MD5.hexdigest(str + secret) == pairs["sig"]) && (pairs["expires"] == "0" || Time.now.to_i < pairs["expires"].to_i)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
facebook_sig_validator-0.1.0 lib/facebook_sig_validator.rb