Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Ruby Gem which parses and validates Facebook signed requests
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.gitignore
.travis.yml
Gemfile
README.md
Rakefile
facebook-signed-request.gemspec

README.md

Usage

    require 'facebook-signed-request'

    # The secret can be set globally
    Facebook::SignedRequest.secret = "dkhsdfhjsd123d2ed3q1wd222qd2"
    request = Facebook::SignedRequest.new( params[:signed_request] )

    # or as an optional parameter for individual calls
    request = Facebook::SignedRequest.new( params[:signed_request], secret: secret )

    request.valid?
    # => true / false

    request.errors
    # => [
    #  "Invalid Format. See http://developers.facebook.com/docs/authentication/signed_request/",
    #  "Invalid Base64 encoding for signature",
    #  "Invalid Base64 Encoding for data",
    #  "Invalid JSON object",
    #  "Invalid Algorithm. Expected: HMAC-SHA256",
    #  "Signatures do not match.
    #]

    request.data
    # => {
    #      :algorithm   => "HMAC-SHA256",
    #      :expires     => 1308988800,
    #      :issued_at   => 1308985018,
    #      :oauth_token => "114998258593813|2.AQBAttRlLVnwqNPZ.3600.1308988800…",
    #      :user => {
    #        :country => "de",
    #        :locale  => "en_US",
    #        :age     => {"min"=>21}
    #      },
    #      :user_id => "100000656666199"
    #    }


    Facebook::SignedRequest.encode_and_sign { :foo => bar }
    # => g_eE3hoQDPKFusHcc_Tj7k2xxo3mCKsOEXKMViq0pAY=.eyJmb28iOiJiYXIifQ==

Run the tests with rake test:units

Something went wrong with that request. Please try again.