Updated Facebook login method

This commit is contained in:
Fosco Marotto
2016-01-30 15:20:44 -08:00
parent 774de7b4c6
commit f05fb7d9fd
5 changed files with 19 additions and 4 deletions

View File

@@ -20,6 +20,7 @@ function Config(applicationId, mount) {
this.dotNetKey = cacheInfo.dotNetKey; this.dotNetKey = cacheInfo.dotNetKey;
this.restAPIKey = cacheInfo.restAPIKey; this.restAPIKey = cacheInfo.restAPIKey;
this.fileKey = cacheInfo.fileKey; this.fileKey = cacheInfo.fileKey;
this.facebookAppIds = cacheInfo.facebookAppIds;
this.mount = mount; this.mount = mount;
} }

View File

@@ -17,6 +17,7 @@ There is a development wiki here on GitHub: https://github.com/ParsePlatform/par
* masterKey (required) - The master key to use for overriding ACL security * masterKey (required) - The master key to use for overriding ACL security
* cloud - The absolute path to your cloud code main.js file * cloud - The absolute path to your cloud code main.js file
* fileKey - For migrated apps, this is necessary to provide access to files already hosted on Parse. * fileKey - For migrated apps, this is necessary to provide access to files already hosted on Parse.
* facebookAppIds - An array of valid Facebook application IDs.
#### Client key options: #### Client key options:

View File

@@ -219,7 +219,7 @@ RestWrite.prototype.handleFacebookAuthData = function() {
return facebook.validateUserId(facebookData.id, return facebook.validateUserId(facebookData.id,
facebookData.access_token) facebookData.access_token)
.then(() => { .then(() => {
return facebook.validateAppId(process.env.FACEBOOK_APP_ID, return facebook.validateAppId(this.config.facebookAppIds,
facebookData.access_token); facebookData.access_token);
}).then(() => { }).then(() => {
// Check if this user already exists // Check if this user already exists

View File

@@ -16,10 +16,15 @@ function validateUserId(userId, access_token) {
} }
// Returns a promise that fulfills iff this app id is valid. // Returns a promise that fulfills iff this app id is valid.
function validateAppId(appId, access_token) { function validateAppId(appIds, access_token) {
if (!appIds.length) {
throw new Parse.Error(
Parse.Error.OBJECT_NOT_FOUND,
'Facebook auth is not configured.');
}
return graphRequest('app?access_token=' + access_token) return graphRequest('app?access_token=' + access_token)
.then((data) => { .then((data) => {
if (data && data.id == appId) { if (data && appIds.contains(data.id)) {
return; return;
} }
throw new Parse.Error( throw new Parse.Error(

View File

@@ -26,6 +26,8 @@ addParseCloud();
// "cloud": relative location to cloud code to require // "cloud": relative location to cloud code to require
// "appId": the application id to host // "appId": the application id to host
// "masterKey": the master key for requests to this app // "masterKey": the master key for requests to this app
// "facebookAppIds": an array of valid Facebook Application IDs, required
// if using Facebook login
// "collectionPrefix": optional prefix for database collection names // "collectionPrefix": optional prefix for database collection names
// "fileKey": optional key from Parse dashboard for supporting older files // "fileKey": optional key from Parse dashboard for supporting older files
// hosted by Parse // hosted by Parse
@@ -59,9 +61,15 @@ function ParseServer(args) {
javascriptKey: args.javascriptKey || '', javascriptKey: args.javascriptKey || '',
dotNetKey: args.dotNetKey || '', dotNetKey: args.dotNetKey || '',
restAPIKey: args.restAPIKey || '', restAPIKey: args.restAPIKey || '',
fileKey: args.fileKey || 'invalid-file-key' fileKey: args.fileKey || 'invalid-file-key',
facebookAppIds: args.facebookAppIds || []
}; };
// To maintain compatibility. TODO: Remove in v2.1
if (process.env.FACEBOOK_APP_ID) {
cache.apps[args.appId]['facebookAppIds'].push(process.env.FACEBOOK_APP_ID);
}
// Initialize the node client SDK automatically // Initialize the node client SDK automatically
Parse.initialize(args.appId, args.javascriptKey || '', args.masterKey); Parse.initialize(args.appId, args.javascriptKey || '', args.masterKey);