facebook-sdk
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -850,3 +850,13 @@ /** | ||
_getCurrentUrl: function() { | ||
var site = URL.parse(this.siteUrl); | ||
if (this.siteUrl) { | ||
var site = URL.parse(this.siteUrl); | ||
} else if (this.request && this.request.headers.host) { | ||
var site = { | ||
protocol: 'http:', // TODO: can we detect this? | ||
host: this.request.headers.host | ||
}; | ||
} else { | ||
throw new Error('No host or siteUrl available'); | ||
} | ||
var url = URL.parse(this.request.url, true); | ||
@@ -853,0 +863,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"keywords": ["facebook", "sdk", "graph", "api", "connect", "canvas"], | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"author": "Christopher Johnson <tenorviol@yahoo.com> (http://github.com/tenorviol)", | ||
@@ -8,0 +8,0 @@ "repository" : { |
@@ -20,73 +20,33 @@ [node.js Facebook SDK](https://github.com/tenorviol/node-facebook-sdk) | ||
Usage | ||
----- | ||
Use as connect middleware | ||
------------------------- | ||
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/). | ||
The following will attach a new Facebook object to each incoming http request. | ||
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'), | ||
http = require('http'); | ||
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>'); | ||
} | ||
}).listen(80); | ||
Usage as connect middleware | ||
--------------------------- | ||
Using this as connect middleware, the following will attach a facebook object | ||
to each incoming http request. | ||
var app = connect() | ||
connect() | ||
.use(fbsdk.facebook({ | ||
appId : 'YOUR APP ID', | ||
secret : 'YOUR API SECRET', | ||
siteUrl: 'http://yoursite.com', | ||
})). | ||
use(connect.router(function(app) { | ||
secret : 'YOUR API SECRET' | ||
})) | ||
.use(connect.router(function(app) { | ||
app.get('/', function(req, res, next) { | ||
if (req.facebook.getSession()) { | ||
res.end('<a href="' + req.facebook.getLogoutUrl() + '">Logout</a>'); | ||
// get my graph api information | ||
facebook.api('/me', function(me) { | ||
console.log(me); | ||
}); | ||
} else { | ||
res.end('<a href="' + req.facebook.getLoginUrl() + '">Login</a>'); | ||
} | ||
}); | ||
})); | ||
})) | ||
.listen(3000); | ||
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 | ||
@@ -93,0 +53,0 @@ ----- |
@@ -472,6 +472,6 @@ /** | ||
httpServerTest(options, function(request, response) { | ||
request.headers.host = 'fbrell.com'; | ||
var facebook = new fbsdk.Facebook({ | ||
appId : APP_ID, | ||
secret : SECRET, | ||
siteUrl: 'http://fbrell.com/', | ||
request: request | ||
@@ -485,2 +485,33 @@ }); | ||
// The siteUrl option trumps the 'host' header | ||
exports.testLoginURLUsingSiteUrl = function(test) { | ||
var options = { | ||
path: '/examples' | ||
}; | ||
httpServerTest(options, function(request, response) { | ||
test.ok(request.headers.host != 'fbrell.com'); | ||
var facebook = new fbsdk.Facebook({ | ||
appId : APP_ID, | ||
secret : SECRET, | ||
siteUrl: 'http://fbrell.com', | ||
request: request | ||
}); | ||
var encodedUrl = querystring.escape('http://fbrell.com/examples'); | ||
test.ok(facebook.getLoginUrl().indexOf(encodedUrl) >= 0, 'Expect the current url to exist.'); | ||
test.done(); | ||
}); | ||
}; | ||
exports.testUnavailableLoginURLThrowsError = function(test) { | ||
var facebook = new fbsdk.Facebook({ | ||
appId : APP_ID, | ||
secret : SECRET | ||
}); | ||
test.expect(1); | ||
test['throws'](function() { | ||
facebook.getLoginUrl(); | ||
}); | ||
test.done(); | ||
}; | ||
exports.testLoginURLDefaultsDropSessionQueryParam = function(test) { | ||
@@ -491,6 +522,6 @@ var options = { | ||
httpServerTest(options, function(request, response) { | ||
request.headers.host = 'fbrell.com'; | ||
var facebook = new fbsdk.Facebook({ | ||
appId : APP_ID, | ||
secret : SECRET, | ||
siteUrl: 'http://fbrell.com/', | ||
request: request | ||
@@ -510,6 +541,6 @@ }); | ||
httpServerTest(options, function(request, response) { | ||
request.headers.host = 'fbrell.com'; | ||
var facebook = new fbsdk.Facebook({ | ||
appId : APP_ID, | ||
secret : SECRET, | ||
siteUrl: 'http://fbrell.com/', | ||
request: request | ||
@@ -529,6 +560,6 @@ }); | ||
httpServerTest(options, function(request, response) { | ||
request.headers.host = 'fbrell.com'; | ||
var facebook = new fbsdk.Facebook({ | ||
appId : APP_ID, | ||
secret : SECRET, | ||
siteUrl: 'http://fbrell.com/', | ||
request: request | ||
@@ -554,6 +585,6 @@ }); | ||
httpServerTest(options, function(request, response) { | ||
request.headers.host = 'fbrell.com'; | ||
var facebook = new fbsdk.Facebook({ | ||
appId : APP_ID, | ||
secret : SECRET, | ||
siteUrl: 'http://fbrell.com/', | ||
request: request | ||
@@ -572,6 +603,6 @@ }); | ||
httpServerTest(options, function(request, response) { | ||
request.headers.host = 'fbrell.com'; | ||
var facebook = new fbsdk.Facebook({ | ||
appId : APP_ID, | ||
secret : SECRET, | ||
siteUrl: 'http://fbrell.com/', | ||
request: request | ||
@@ -590,6 +621,6 @@ }); | ||
httpServerTest(options, function(request, response) { | ||
request.headers.host = 'fbrell.com'; | ||
var facebook = new fbsdk.Facebook({ | ||
appId : APP_ID, | ||
secret : SECRET, | ||
siteUrl: 'http://fbrell.com/', | ||
request: request | ||
@@ -601,4 +632,4 @@ }); | ||
var loginStatusUrl = facebook.getLoginStatusUrl({ ok_session: okUrl }); | ||
test.ok(loginStatusUrl.indexOf(encodedUrl1), 'Expect the current url to exist.'); | ||
test.ok(loginStatusUrl.indexOf(encodedUrl2), 'Expect the custom url to exist.'); | ||
test.ok(loginStatusUrl.indexOf(encodedUrl1) >= 0, 'Expect the current url to exist.'); | ||
test.ok(loginStatusUrl.indexOf(encodedUrl2) >= 0, 'Expect the custom url to exist.'); | ||
test.done(); | ||
@@ -613,10 +644,11 @@ }); | ||
httpServerTest(options, function(request, response) { | ||
request.headers.host = 'fbrell.com:8080'; | ||
var facebook = new fbsdk.Facebook({ | ||
appId : APP_ID, | ||
secret : SECRET, | ||
siteUrl: 'http://fbrell.com:8080/', | ||
request: request | ||
}); | ||
var encodedUrl = querystring.escape('http://fbrell.com:8080/examples'); | ||
test.ok(facebook.getLoginUrl().indexOf(encodedUrl), 'Expect the current url to exist.'); | ||
console.log(facebook.getLoginUrl()); | ||
test.ok(facebook.getLoginUrl().indexOf(encodedUrl) >= 0, 'Expect the current url to exist.'); | ||
test.done(); | ||
@@ -626,2 +658,3 @@ }); | ||
// TODO: currently there it is only possible to do this with a siteUrl | ||
exports.testSecureCurrentUrl = function(test) { | ||
@@ -639,3 +672,3 @@ var options = { | ||
var encodedUrl = querystring.escape('https://fbrell.com/examples'); | ||
test.ok(facebook.getLoginUrl().indexOf(encodedUrl), 'Expect the current url to exist.'); | ||
test.ok(facebook.getLoginUrl().indexOf(encodedUrl) >= 0, 'Expect the current url to exist.'); | ||
test.done(); | ||
@@ -645,2 +678,3 @@ }); | ||
// TODO: do this without siteUrl? | ||
exports.testSecureCurrentUrlWithNonDefaultPort = function(test) { | ||
@@ -658,3 +692,3 @@ var options = { | ||
var encodedUrl = querystring.escape('https://fbrell.com:8080/examples'); | ||
test.ok(facebook.getLoginUrl().indexOf(encodedUrl), 'Expect the current url to exist.'); | ||
test.ok(facebook.getLoginUrl().indexOf(encodedUrl) >= 0, 'Expect the current url to exist.'); | ||
test.done(); | ||
@@ -661,0 +695,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52574
1595
57