facebook-node-sdk
Advanced tools
Comparing version 0.0.1 to 0.1.0
@@ -28,4 +28,4 @@ var https = require('https'); | ||
var state = this.getPersistentData('state'); | ||
if (state === null) { | ||
this.state = this.getPersistentData('state'); | ||
if (state) { | ||
this.state = state; | ||
} | ||
@@ -63,10 +63,2 @@ } | ||
BaseFacebook.prototype.setCookie = function(key, value) { | ||
if (!this.request || !this.request.cookies) { | ||
throw new Error('Cookie unsupported!'); | ||
} | ||
this.request.cookies[key] = value; | ||
return this; | ||
}; | ||
BaseFacebook.prototype.appId = null; | ||
@@ -218,25 +210,3 @@ | ||
var self = this; | ||
this.getAccessTokenFromCode(code, null, function(err, accessToken) { | ||
if (err) { | ||
callback(err, null); | ||
callback = null; | ||
} | ||
else { | ||
if (accessToken) { | ||
self.setPersistentData('code', code); | ||
self.setPersistentData('access_token', accessToken); | ||
callback(null, accessToken); | ||
callback = null; | ||
} | ||
else { | ||
// signed request states there's no access token, so anything | ||
// stored should be cleared. | ||
self.clearAllPersistentData(); | ||
// respect the signed request's data, even | ||
// if there's an authorization code or something else | ||
callback(null, false); | ||
callback = null; | ||
} | ||
} | ||
}); | ||
this.getAccessTokenFromCode(code, null, handleAccessTokenFromCode); | ||
} | ||
@@ -258,22 +228,3 @@ else { | ||
var self = this; | ||
this.getAccessTokenFromCode(code, null, function(err, accessToken) { | ||
if (err) { | ||
callback(err, null); | ||
callback = null; | ||
} | ||
else { | ||
if (accessToken) { | ||
self.setPersistentData('code', code); | ||
self.setPersistentData('access_token', accessToken); | ||
callback(null, accessToken); | ||
callback = null; | ||
} | ||
else { | ||
// code was bogus, so everything based on it should be invalidated. | ||
self.clearAllPersistentData(); | ||
callback(null, false); | ||
callback = null; | ||
} | ||
} | ||
}); | ||
this.getAccessTokenFromCode(code, null, handleAccessTokenFromCode); | ||
} | ||
@@ -289,2 +240,25 @@ else { | ||
} | ||
function handleAccessTokenFromCode(err, accessToken) { | ||
if (err) { | ||
callback(err, null); | ||
callback = null; | ||
} | ||
else { | ||
if (accessToken) { | ||
self.setPersistentData('code', code); | ||
self.setPersistentData('access_token', accessToken); | ||
callback(null, accessToken); | ||
callback = null; | ||
} | ||
else { | ||
// signed request states there's no access token, so anything | ||
// stored should be cleared. | ||
self.clearAllPersistentData(); | ||
// respect the signed request's data, even | ||
// if there's an authorization code or something else | ||
callback(null, false); | ||
callback = null; | ||
} | ||
} | ||
} | ||
}; | ||
@@ -514,13 +488,26 @@ | ||
else { | ||
if (accessToken && accessToken !== self.getApplicationAccessToken() && | ||
!(user && persistedAccessToken === accessToken)) { | ||
self.getUserFromAccessToken(function(err, user) { | ||
if (user) { | ||
self.setPersistentData('user_id', user); | ||
} else { | ||
self.clearAllPersistentData(); | ||
if (accessToken) { | ||
// access_token is not application access_token | ||
if (accessToken !== self.getApplicationAccessToken()) { | ||
// undefined user or access_token is old | ||
if (!user || persistedAccessToken !== accessToken) { | ||
self.getUserFromAccessToken(function(err, user) { | ||
if (user) { | ||
self.setPersistentData('user_id', user); | ||
} else { | ||
self.clearAllPersistentData(); | ||
} | ||
callback(null, user); | ||
callback = null; | ||
}); | ||
} | ||
else { | ||
callback(null, user); | ||
callback = null; | ||
} | ||
} | ||
else { | ||
callback(null, user); | ||
callback = null; | ||
}); | ||
} | ||
} | ||
@@ -780,3 +767,3 @@ else { | ||
var sig = this.base64UrlDecode(encodedSig); | ||
var data = JSON.parse(this.base64UrlDecode(payload)); | ||
var data = JSON.parse(this.base64UrlDecode(payload).toString('utf8')); | ||
@@ -833,2 +820,25 @@ if (data.algorithm.toUpperCase() !== 'HMAC-SHA256') { | ||
/** | ||
* Retrieves the UID with the understanding that | ||
* $this->accessToken has already been set and is | ||
* seemingly legitimate. It relies on Facebook's Graph API | ||
* to retrieve user information and then extract | ||
* the user ID. | ||
* | ||
* @return integer Returns the UID of the Facebook user, or 0 | ||
* if the Facebook user could not be determined. | ||
*/ | ||
BaseFacebook.prototype.getUserFromAccessToken = function(callback) { | ||
this.api('/me', function(err, userInfo) { | ||
if (err) { | ||
callback(null, 0); | ||
callback = null; | ||
} | ||
else { | ||
callback(null, userInfo.id); | ||
callback = null; | ||
} | ||
}); | ||
}; | ||
/** | ||
* Retrieves an access token for the given authorization code | ||
@@ -883,3 +893,3 @@ * (previously generated from www.facebook.com on behalf of | ||
var responseParams = querystring.parse(responseParams); | ||
if (responseParams.hasOwnProperty('access_token')) { | ||
if (!responseParams.hasOwnProperty('access_token')) { | ||
callback(null, false); | ||
@@ -1122,2 +1132,5 @@ callback = null; | ||
// for test | ||
BaseFacebook.FacebookApiError = FacebookApiError; | ||
module.exports = BaseFacebook; |
{ | ||
"name": "facebook-node-sdk", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Node.js SDK for the Facebook API", | ||
@@ -21,5 +21,6 @@ "tags": ["facebook"], | ||
"devDependencies": { | ||
"nodeunit": ">=0.6.4" | ||
"expresso": ">=0.9.2", | ||
"express": ">=2.5.1" | ||
}, | ||
"main": "./lib/facebook" | ||
} |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
82136
9
2401
2
15
2