strongloop / loopback-example-passport

LoopBack example for facebook login
Other
185 stars 134 forks source link

Facebook no longer returns all fields by default #50

Closed clockworkgr closed 8 years ago

clockworkgr commented 9 years ago

More of a heads up for anyone coming across this.

New Apps created in facebook automatically get v2.4 + Graph API and both versioned/unversioned requests are upgraded to 2.4.

Hence: https://graph.facebook.com/v2.2/me with ClientID/ClientSecret from a new app returns ONLY id + name. Even though it's versioned it uses v2.4+)

In order to return to the old behaviour and get the same fields we need to explicitly call

https://graph.facebook.com/v2.2/me?fields=first_name,gender,last_name,link,locale,name,timezone,verified,email,updated_time

This is possible with the profileFields field in the AuthStrategy options.

So providers.json.template should include:

"profileFields": ["gender","link","locale","name","timezone","verified","email","updated_time"],

for the facebook-login provider to function as expected

jannyHou commented 9 years ago

@clockworkgr Thanks for informing us this change! I will look into it.

jannyHou commented 9 years ago

hey @clockworkgr, your solution works fine, the complete link returns a bunch of information. But we would appreciate it to be a user defined behaviour :) so feel free to change it on your own app, modify this line would be ok: https://github.com/jaredhanson/passport-facebook/blob/master/lib/strategy.js#L59 We would also include this suggestion in doc.Thank you!

jannyHou commented 8 years ago

Thanks @loay ! For declaring this implementation in loopback-component-passport README.md:

If more info is required from the Facebook profile such as email, it could still be obtained. In node_modules\passport-facebook\lib\strategy.js, replace:

this._profileURL = options.profileURL || 'https://graph.facebook.com/me';

with

this._profileURL = options.profileURL ||
    'https://graph.facebook.com/v2.2/me?fields=first_name,gender,last_name,link,locale,name,timezone,verified,email,updated_time';
princecharmx commented 8 years ago

@clockworkgr suggestions looks more clean than the suggestion of changing the profileUrl in the code.

providers.json.template should include: "profileFields": ["gender","link","locale","name","timezone","verified","email","updated_time"],

ggiacomo commented 8 years ago

OMG why this solution is not in the official documentation?! Please update this page https://docs.strongloop.com/display/public/LB/Tutorial%3A+third-party+login

superkhau commented 8 years ago

@crandmck ^

crandmck commented 8 years ago

@superkhau I updated http://loopback.io/doc/en/lb2/Configuring-providers.json.html#example-providersjson but now we need to update as well https://github.com/strongloop/loopback-example-passport/blob/master/providers.json.template.

I'll leave that to you or @jannyHou.

jannyHou commented 8 years ago

Thank you @crandmck . Created a pr to update it in example repo: https://github.com/strongloop/loopback-example-passport/pull/83