Skip to content

Commit a0f6fa4

Browse files
author
Fatima A. Alansari
committed
Fixes #53 fixes #43
Due to changes to the Facebook API, the user's Facebook name and e-mail address return as undefined undefined, and undefined respectively. This PR addresses these issues, hopefully successfully fixing them. Changes made: 1. In auth.js: under Facebook, 'profileFields' was added for requesting permissions from the FB API. 2. In routes.js: 'public_profile' was added to the FB permissions scope. Although FB provides this by default to an app that was granted access by a user, it is considered best practice to declare all requested permissions. 3. In user.js: under facebook, name was changed to be before email field. Their order is the reason behind issue #43, where email id returns as undefined.
1 parent a3a6b88 commit a0f6fa4

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

app/models/user.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ var userSchema = mongoose.Schema({
1212
facebook : {
1313
id : String,
1414
token : String,
15-
email : String,
16-
name : String
15+
name : String,
16+
email : String
1717
},
1818
twitter : {
1919
id : String,

app/routes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ module.exports = function(app, passport) {
5454
// facebook -------------------------------
5555

5656
// send to facebook to do the authentication
57-
app.get('/auth/facebook', passport.authenticate('facebook', { scope : 'email' }));
57+
app.get('/auth/facebook', passport.authenticate('facebook', { scope : ['public_profile', 'email'] }));
5858

5959
// handle the callback after facebook has authenticated the user
6060
app.get('/auth/facebook/callback',
@@ -105,7 +105,7 @@ module.exports = function(app, passport) {
105105
// facebook -------------------------------
106106

107107
// send to facebook to do the authentication
108-
app.get('/connect/facebook', passport.authorize('facebook', { scope : 'email' }));
108+
app.get('/connect/facebook', passport.authorize('facebook', { scope : ['public_profile', 'email'] }));
109109

110110
// handle the callback after facebook has authorized the user
111111
app.get('/connect/facebook/callback',

config/auth.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ module.exports = {
77
'clientID' : 'your-secret-clientID-here', // your App ID
88
'clientSecret' : 'your-client-secret-here', // your App Secret
99
'callbackURL' : 'http://localhost:8080/auth/facebook/callback',
10-
'profileURL': 'https://graph.facebook.com/v2.5/me?fields=first_name,last_name,email'
10+
'profileURL': 'https://graph.facebook.com/v2.5/me?fields=first_name,last_name,email',
11+
'profileFields' : ['id', 'email', 'name'] // For requesting permissions from Facebook API
1112

1213
},
1314

0 commit comments

Comments
 (0)