Get signed_request in Node.js (Express) Facebook canvas app

is there any way how to get and parse signed_request in Node.js Facebook page tab app? I need to know page id and if user liked the page...


I did this a little while ago, and ended up writing a small library to do it. The original CoffeeScript can be found at, here is a JavaScript translation:

var crypto = require('crypto');

SignedRequest = (function() {

  function SignedRequest(secret, request) {
    this.secret = secret;
    this.request = request;
    this.verify = this.verify.bind(this);

    var parts = this.request.split('.');
    this.encodedSignature = parts[0];
    this.encoded = parts[1];
    this.signature = this.base64decode(this.encodedSignature);
    this.decoded = this.base64decode(this.encoded); = JSON.parse(this.decoded);

  SignedRequest.prototype.verify = function() {
    if ( !== 'HMAC-SHA256') {
      return false;
    var hmac = crypto.createHmac('SHA256', this.secret);
    var result = hmac.digest('base64').replace(/\//g, '_').replace(/\+/g, '-').replace(/\=/g, '');
    return result === this.encodedSignature;

  SignedRequest.prototype.base64encode = function(data) {
    return new Buffer(data, 'utf8').toString('base64').replace(/\//g, '_').replace(/\+/g, '-').replace(/\=/g, '');

  SignedRequest.prototype.base64decode = function(data) {
    while (data.length % 4 !== 0) {
      data += '=';
    data = data.replace(/-/g, '+').replace(/_/g, '/');
    return new Buffer(data, 'base64').toString('utf-8');

  return SignedRequest;


module.exports = SignedRequest;

Which you can use like this:

var verifier = new SignedRequest(clientSecret, signedRequest);
verifier.verify() // whether or not the signed request verifies // the data from the signed request

Need Your Help

How to stay under GAE quotas? Algorithm design

python algorithm google-app-engine

I have a function in my app that uses a lot of resources, and takes time to execute.

How did fogbugz implement its screenshot feature?

fogbugz webpage-screenshot

Does anyone know how FogBugz implemented the "taking a screenshot of the current work screen" feature? Is this done purely via php? Perl? A flash script?