Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

facebook-sdk

Package Overview
Dependencies
Maintainers
0
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

facebook-sdk - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

test/connect.js

34

lib/facebook.js

@@ -94,2 +94,13 @@ /**

// experimental connect middleware
// TODO: maybe this should be renamed?
//exports.facebook = function(config) {
// return function(req, res, next) {
// req.facebook = new Facebook(config);
// req.facebook.request = req;
// req.facebook.response = res;
// next();
// };
//};
/**

@@ -101,2 +112,3 @@ * Initialize the Facebook Application, providing access to the Facebook platform API.

* - secret: the application secret
* TODO: default to use req.headers.host and req.method
* - siteUrl: (optional) url of the Facebook app, used for generating next/cancel urls

@@ -111,10 +123,22 @@ * - request: (optional) http.ServerRequest for reclaiming sessions

*/
var Facebook = exports.Facebook = function(config) {
if (!(this instanceof Facebook)) {
return new Facebook(config);
var Facebook = exports.facebook = exports.Facebook = function(config) {
var object;
if (this instanceof Facebook) {
// instantiation using the 'new' operator
facebook = this;
} else {
// connect style middleware function
facebook = function(req, res, next) {
req.facebook = new Facebook(config);
req.facebook.request = req;
req.facebook.response = res;
next();
};
}
for (var i in config) {
this[i] = config[i];
facebook[i] = config[i];
}
return facebook;
};

@@ -264,3 +288,3 @@

if (split > 0) {
cookies[cookie.substr(0, split).trim()] = querystring.unescape(cookie.substr(split + 1).trim());
cookies[cookie.substr(0, split).trim()] = querystring.unescape(cookie.substr(split + 1)).trim();
}

@@ -267,0 +291,0 @@ });

2

package.json

@@ -5,3 +5,3 @@ {

"keywords": ["facebook", "sdk", "graph", "api", "connect", "canvas"],
"version": "0.2.2",
"version": "0.2.3",
"author": "Christopher Johnson <tenorviol@yahoo.com> (http://github.com/tenorviol)",

@@ -8,0 +8,0 @@ "repository" : {

@@ -11,44 +11,82 @@ [node.js Facebook SDK](https://github.com/tenorviol/node-facebook-sdk)

The node.js Facebook SDK is licensed under the Apache License, Version 2.0
(http://www.apache.org/licenses/LICENSE-2.0.html), as was the original library.
The node.js Facebook SDK is licensed under the
[Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html),
as was the original library.
Install
-------
npm install facebook-sdk
Usage
-----
First, create a Facebook SDK object. The http request and response objects are not
required for application graph requests or when setting the session manually. Otherwise
they are recommended, for reading and verification of of the session from the request
or cookie data, and for writing verified session data to the browser's cookie.
Create a Facebook SDK object. The `request` lets the object retrieve the
user's session from the http header. The `response` lets the object write
the user a new session cookie. For more information on querying Facebook's
graph api, see [developers.facebook.com](http://developers.facebook.com/docs/reference/api/).
var fbsdk = require('facebook-sdk');
var fbsdk = require('facebook-sdk'),
http = require('http');
var facebook = new fbsdk.Facebook({
appId : 'YOUR APP ID',
secret : 'YOUR API SECRET',
request : request (http.ServerRequest),
response : response (http.ServerResponse)
});
To make [API][API] calls:
facebook.api('/me', function(me) {
if (me.error) {
console.log(me);
return;
http.createServer(function(request, response) {
// create a facebook object
var facebook = new fbsdk.Facebook({
appId : 'YOUR APP ID',
secret : 'YOUR API SECRET',
siteUrl: 'http://yoursite.com',
request : request,
response : response
});
// logged in
if (facebook.getSession()) {
response.end('<a href="' + facebook.getLogoutUrl() + '">Logout</a>');
// get my graph api information
facebook.api('/me', function(me) {
console.log(me);
});
// vs logged out
} else {
response.end('<a href="' + facebook.getLoginUrl() + '">Login</a>');
}
// do something interesting
});
}).listen(80);
Logged in vs Logged out:
Usage as connect middleware
---------------------------
if (facebook.getSession()) {
print('<a href="' + facebook.getLogoutUrl() + '">Logout</a>');
} else {
print('<a href="' + facebook.getLoginUrl() + '">Login</a>');
}
Using this as connect middleware, the following will attach a facebook object
to each incoming http request.
[API]: http://developers.facebook.com/docs/api
var app = connect()
.use(fbsdk.facebook({
appId : 'YOUR APP ID',
secret : 'YOUR API SECRET',
siteUrl: 'http://yoursite.com',
})).
use(connect.router(function(app) {
app.get('/', function(req, res, next) {
if (req.facebook.getSession()) {
res.end('<a href="' + req.facebook.getLogoutUrl() + '">Logout</a>');
} else {
res.end('<a href="' + req.facebook.getLoginUrl() + '">Login</a>');
}
});
}));
Open question about the above middleware
----------------------------------------
Creating an adhoc object is done with `new fbsdk.Facebook({...})`, and
creating middleware functions is `fbsdk.facebook({...})`. This strikes
me as an ugly over-use of case sensitivity. Anybody with a better idea
about this api, please message me.
Tests

@@ -59,2 +97,2 @@ -----

the new node.js library works as expected. Some new tests have been added to cover
edge cases, and others that are not relevant in the new environment have been removed.
edge cases, and others not relevant in the new environment have been removed.
/**
* Copyright 2011 Facebook, Inc.
* Copyright 2011 Christopher Johnson <tenorviol@yahoo.com>

@@ -36,2 +37,7 @@ *

// cookie copied from testSetSession
var SESSION_COOKIE = 'fbs_117743971608120=%22access_token%3D117743971608120%257C2.vdCKd4ZIEJlHwwtrkilgKQ__.86400.1281049200-1677846385%257CNF_2DDNxFBznj2CuwiwabHhTAHc.%26expires%3D1281049200%26secret%3Du0QiRGAwaPCyQ7JE_hiz1w__%26session_key%3D2.vdCKd4ZIEJlHwwtrkilgKQ__.86400.1281049200-1677846385%26sig%3D7a9b063de0bef334637832166948dcad%26uid%3D1677846385%22';
// cookie copied from Facebook's Javascript SDK running on Safari
var UNESCAPED_SESSION_COOKIE = 'junk=foo; fbs_117743971608120="access_token=117743971608120%7C2.vdCKd4ZIEJlHwwtrkilgKQ__.86400.1281049200-1677846385%7CNF_2DDNxFBznj2CuwiwabHhTAHc.&expires=1281049200&secret=u0QiRGAwaPCyQ7JE_hiz1w__&session_key=2.vdCKd4ZIEJlHwwtrkilgKQ__.86400.1281049200-1677846385&sig=7a9b063de0bef334637832166948dcad&uid=1677846385"';
var VALID_SIGNED_REQUEST = '1sxR88U4SW9m6QnSxwCEw_CObqsllXhnpP5j2pxD97c.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImV4cGlyZXMiOjEyODEwNTI4MDAsIm9hdXRoX3Rva2VuIjoiMTE3NzQzOTcxNjA4MTIwfDIuVlNUUWpub3hYVVNYd1RzcDB1U2g5d19fLjg2NDAwLjEyODEwNTI4MDAtMTY3Nzg0NjM4NXx4NURORHBtcy1nMUM0dUJHQVYzSVdRX2pYV0kuIiwidXNlcl9pZCI6IjE2Nzc4NDYzODUifQ';

@@ -167,3 +173,3 @@ var NON_TOSSED_SIGNED_REQUEST = 'c0Ih6vYvauDwncv0n0pndr0hP0mvZaJPQDPt6Z43O0k.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiJ9';

test.equal(name, 'Set-Cookie');
test.equal(value, 'fbs_117743971608120=%22access_token%3D117743971608120%257C2.vdCKd4ZIEJlHwwtrkilgKQ__.86400.1281049200-1677846385%257CNF_2DDNxFBznj2CuwiwabHhTAHc.%26expires%3D1281049200%26secret%3Du0QiRGAwaPCyQ7JE_hiz1w__%26session_key%3D2.vdCKd4ZIEJlHwwtrkilgKQ__.86400.1281049200-1677846385%26sig%3D7a9b063de0bef334637832166948dcad%26uid%3D1677846385%22; expires=Thu, 05 Aug 2010 23:00:00 GMT; path=/; domain=.foo.com');
test.equal(value, SESSION_COOKIE+'; expires=Thu, 05 Aug 2010 23:00:00 GMT; path=/; domain=.foo.com');
}

@@ -189,4 +195,3 @@ };

headers: {
// cookie copied from the above testSetSession
cookie: 'fbs_117743971608120=%22access_token%3D117743971608120%257C2.vdCKd4ZIEJlHwwtrkilgKQ__.86400.1281049200-1677846385%257CNF_2DDNxFBznj2CuwiwabHhTAHc.%26expires%3D1281049200%26secret%3Du0QiRGAwaPCyQ7JE_hiz1w__%26session_key%3D2.vdCKd4ZIEJlHwwtrkilgKQ__.86400.1281049200-1677846385%26sig%3D7a9b063de0bef334637832166948dcad%26uid%3D1677846385%22'
cookie: SESSION_COOKIE
}

@@ -209,4 +214,3 @@ };

headers: {
// cookie copied from Facebook's Javascript SDK running on Safari
cookie: 'junk=foo; fbs_117743971608120="access_token=117743971608120%7C2.vdCKd4ZIEJlHwwtrkilgKQ__.86400.1281049200-1677846385%7CNF_2DDNxFBznj2CuwiwabHhTAHc.&expires=1281049200&secret=u0QiRGAwaPCyQ7JE_hiz1w__&session_key=2.vdCKd4ZIEJlHwwtrkilgKQ__.86400.1281049200-1677846385&sig=7a9b063de0bef334637832166948dcad&uid=1677846385"'
cookie: UNESCAPED_SESSION_COOKIE
}

@@ -213,0 +217,0 @@ };

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc