Skip to content

Commit 523fa31

Browse files
committed
Merge pull request parse-community#86 from ParsePlatform/fosco.fb
Updated Facebook login method
2 parents 4b48e01 + f05fb7d commit 523fa31

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

Config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function Config(applicationId, mount) {
2020
this.dotNetKey = cacheInfo.dotNetKey;
2121
this.restAPIKey = cacheInfo.restAPIKey;
2222
this.fileKey = cacheInfo.fileKey;
23+
this.facebookAppIds = cacheInfo.facebookAppIds;
2324
this.mount = mount;
2425
}
2526

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ There is a development wiki here on GitHub: https://github.com/ParsePlatform/par
1717
* masterKey (required) - The master key to use for overriding ACL security
1818
* cloud - The absolute path to your cloud code main.js file
1919
* fileKey - For migrated apps, this is necessary to provide access to files already hosted on Parse.
20+
* facebookAppIds - An array of valid Facebook application IDs.
2021

2122
#### Client key options:
2223

RestWrite.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ RestWrite.prototype.handleFacebookAuthData = function() {
219219
return facebook.validateUserId(facebookData.id,
220220
facebookData.access_token)
221221
.then(() => {
222-
return facebook.validateAppId(process.env.FACEBOOK_APP_ID,
222+
return facebook.validateAppId(this.config.facebookAppIds,
223223
facebookData.access_token);
224224
}).then(() => {
225225
// Check if this user already exists

facebook.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ function validateUserId(userId, access_token) {
1616
}
1717

1818
// Returns a promise that fulfills iff this app id is valid.
19-
function validateAppId(appId, access_token) {
19+
function validateAppId(appIds, access_token) {
20+
if (!appIds.length) {
21+
throw new Parse.Error(
22+
Parse.Error.OBJECT_NOT_FOUND,
23+
'Facebook auth is not configured.');
24+
}
2025
return graphRequest('app?access_token=' + access_token)
2126
.then((data) => {
22-
if (data && data.id == appId) {
27+
if (data && appIds.contains(data.id)) {
2328
return;
2429
}
2530
throw new Parse.Error(

index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ addParseCloud();
2626
// "cloud": relative location to cloud code to require
2727
// "appId": the application id to host
2828
// "masterKey": the master key for requests to this app
29+
// "facebookAppIds": an array of valid Facebook Application IDs, required
30+
// if using Facebook login
2931
// "collectionPrefix": optional prefix for database collection names
3032
// "fileKey": optional key from Parse dashboard for supporting older files
3133
// hosted by Parse
@@ -59,9 +61,15 @@ function ParseServer(args) {
5961
javascriptKey: args.javascriptKey || '',
6062
dotNetKey: args.dotNetKey || '',
6163
restAPIKey: args.restAPIKey || '',
62-
fileKey: args.fileKey || 'invalid-file-key'
64+
fileKey: args.fileKey || 'invalid-file-key',
65+
facebookAppIds: args.facebookAppIds || []
6366
};
6467

68+
// To maintain compatibility. TODO: Remove in v2.1
69+
if (process.env.FACEBOOK_APP_ID) {
70+
cache.apps[args.appId]['facebookAppIds'].push(process.env.FACEBOOK_APP_ID);
71+
}
72+
6573
// Initialize the node client SDK automatically
6674
Parse.initialize(args.appId, args.javascriptKey || '', args.masterKey);
6775

0 commit comments

Comments
 (0)