Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Requesting Fields in Profile #9

sw360cab opened this Issue May 2, 2012 · 13 comments


None yet
5 participants

sw360cab commented May 2, 2012

is it possible to request additional parameters for user profile as specified in official doc http://developers.facebook.com/docs/reference/api/user/

Picture -> The URL of the user's profile pic (only returned if you explicitly specify a 'fields=picture' param)

Is it a possible enhancement or you already planned to handle this?
I can give look iBTW


jaredhanson commented May 3, 2012

Agreed. profileURL or profileFields should be an option to the strategy.

I'll add it to the to-do list. Feel free to send a pull request if you implement this in the meantime.


stevebest commented Jun 20, 2012

Different providers have their own little idiosyncrasies when it comes to requesting fields. Facebook, for once, picks some stupid default set of fields which includes spoken languages and work places, but doesn't include profile picture, and, when requested for ?fields=picture, decides to discard all other fields and demands to specify them all.

I suggest something like stevebest/passport-vkontakte@220b961 instead (lines 161-169). Rather than forcing lib user to cope with specifics of each of the providers' profile schema, isn't it just simpler to request whatever fields a specific provider might support, convert them to a single understandable Portable Contacts-like format and allow the app to pick what it wants?

The downside for this approach is that some providers provide a lot of optional fields in what they think constitutes a user profile. This might include some crazy shit which doesn't even make sense for Portable Contacts. Fetching all possible fields might also be an overkill when all you need is a name and a pic.

it's an interesting solution. Is there any possibility that the field array can be popped and made configurable? this would overtake the limit of pulling all the fields


stevebest commented Jun 20, 2012

Yeah, maybe if we add profileFields as suggested, and treat it not as a direct input for a provider API, but rather as a hint of what fields we'd like to see in profile.

I mean something like following:

// specify what fields we'd like to fetch in Portable Contacts format
passport.authenticate(..., { ... profileFields: ['displayName', 'photos', 'gender'] })

and form a provider-specific request inside a strategy. For example, in case of facebook, when profileFields includes 'photos', we'd like to add picture to a list of ?fields=, which is what fb API expects. And similarly for other providers.

I will look forward if I can help you by pulling your branch


jaredhanson commented Jun 21, 2012

I like the idea of specifying profileFields using keys defined by Portable Contacts, and then mapping them to what the provider expects. That's consistent with the goal of normalizing the strategies as much as possible.

In cases where things don't map cleanly, I suspect we may still want an option pass in provider-specific fields directly, much like the profile._json object is exposed. The downside, of course, is that ties you to a specific version of the provider's API, but sometimes that's the path of least resistance. It'd be good to have a profileFields option that is the preferred approach, and also support a profileURL which can be specified as a string in whatever format the provider expects it (including any fields to query).

I'm currently improving support for API authentication in Passport core, and then I'll start clearing out the backlog of pull requests and issues.

Thanks for the discussion! This is great!


jaredhanson commented Feb 10, 2013

I've merged @stevebest's pull request, so this is now officially supported! (published to npm as passport-facebook v0.1.5)

To fetch a profile with a photo, set the profileFields option:

passport.use(new FacebookStrategy({
    // clientID, clientSecret and callbackURL
    profileFields: ['id', 'displayName', 'photos']
  // verify callback

Alternatively, you can specify the profileURL (including fields) directly:

new FacebookStrategy({
  // clientID, clientSecret and callbackURL
  profileURL: 'https://graph.facebook.com/me?fields=id,username,name,picture'
}, ...)

stevebest commented Feb 11, 2013

Better late than never, I guess :)

Just tried.. Seems working great..thanks @stevebest and @jaredhanson to finally merging

This is great. I wanted to know how do I get access to the profileFields data - in app.get('/auth/facebook/callback',...)?
Is this part of the req object?


sw360cab commented Mar 8, 2013

define the profile fields as @jaredhanson explained above...
Then you will find all the fields in the "profile" object in the callback in the form

function (token, tokenSecret, profile, done){

Thanks - will do.

zloyded commented Apr 21, 2015

passport.use(new FacebookStrategy({
    // clientID, clientSecret and callbackURL
    profileFields: ['id', 'displayName', 'photos']
  // verify callback

Try do like this, will not working 👊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment