Skip to content

Commit

Permalink
Merge branch 'master' of github.com:DracoBlue/node-facebook-client
Browse files Browse the repository at this point in the history
  • Loading branch information
DracoBlue committed Jan 7, 2012
2 parents ddad0c0 + 80d5876 commit 78a57fc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
5 changes: 4 additions & 1 deletion README.md
@@ -1,7 +1,7 @@
node-facebook-client README
===========================

Version: 1.5.0
Version: 1.5.1

Official Site: <http://dracoblue.net/>

Expand Down Expand Up @@ -145,6 +145,9 @@ Calculates the signature for a given set of parameters and the api_secret.
Changelog
---------

- 1.5.1 (2012/01/06)
- fixed isValid: throwed an exception, when user_data.error was not existant
- added backward compatibility for node 0.4.x, if toString('hex') was missing
- 1.5.0 (2012/01/05)
- added support for fbsr-cookie from new facebook auth #16
- added support for lazy-access-token retrieval if oauth-code is given
Expand Down
27 changes: 26 additions & 1 deletion lib/facebook-client/FacebookClient.js
Expand Up @@ -235,13 +235,38 @@ FacebookClient.prototype.getSessionByFbsCookie = function(fbs_cookie) {
};
};

FacebookClient.prototype.convertBase64ToHex = function(base64_string) {
var buffer = new Buffer(base64_string, 'base64');
try
{
return buffer.toString('hex');
}
catch (error)
{
/*
* We actually don't have a toString('hex') implementation, let's do
* it on our own!
*/
var toHex = function (n) {
return ((n < 16) ? '0' : '') + n.toString(16);
}

var hex_string = '';
var length = buffer.length;
for (var i = 0; i < length; i++) {
hex_string += toHex(buffer[i]);
}
return hex_string;
}
};

FacebookClient.prototype.getSessionByFbsrCookie = function(fbsr_cookie) {
var self = this;

return function(cb) {
var facebook_cookie = null;
var fbsr_cookie_parts = fbsr_cookie.split('.');
var signature = new Buffer(fbsr_cookie_parts[0].replace(/\-/g, '+').replace(/\_/g, '/'), 'base64').toString('hex');
var signature = self.convertBase64ToHex(fbsr_cookie_parts[0].replace(/\-/g, '+').replace(/\_/g, '/'));
var payload = fbsr_cookie_parts[1];
var facebook_cookie_raw_json = new Buffer(payload.replace(/\-/g, '+').replace(/\_/g, '/'), 'base64').toString('binary');

Expand Down
2 changes: 1 addition & 1 deletion lib/facebook-client/FacebookSession.js
Expand Up @@ -63,7 +63,7 @@ FacebookSession.prototype.isValid = function() {

return function(cb) {
self.graphCall("/me")(function(user_data){
if (user_data.error)
if (!user_data || user_data.error)
{
cb(false);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name" : "facebook-client",
"version": "1.5.0",
"version": "1.5.1",

"engines": { "node": ">= 0.4.0" },

Expand Down

0 comments on commit 78a57fc

Please sign in to comment.