jaredhanson / passport-facebook

Facebook authentication strategy for Passport and Node.js.
https://www.passportjs.org/packages/passport-facebook/?utm_source=github&utm_medium=referral&utm_campaign=passport-facebook&utm_content=about
MIT License
1.29k stars 447 forks source link

Getting error: FacebookGraphAPIError: (#210) This call requires a Page access token. #233

Closed ryexley closed 6 years ago

ryexley commented 6 years ago

I had facebook auth working, but realized I wasn't actually getting any profile information for the user. I updated my configuration to request information, and now I'm getting the following error when my callback URL is called:

FacebookGraphAPIError: (#210) This call requires a Page access token.
    at /Users/.../node_modules/passport-facebook/lib/strategy.js:165:21
    at passBackControl (/Users/.../node_modules/oauth/lib/oauth2.js:132:9)
    at IncomingMessage.<anonymous> (/Users/.../node_modules/oauth/lib/oauth2.js:157:7)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1055:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)

This is what my express route configuration looks like:

router.get(
    "/facebook/login",
    passport.authenticate( "facebook", { session: false, scope: [ "email", "public_profile", "user_friends" ] } )
);

router.get(
    "/facebook/redirect",
    passport.authenticate( "facebook", { session: false } ),
    generateAccessToken
);

And this is what my facebook strategy configuration/setup looks like:

const facebookAuthConfig = {
    enableProof: true,
    clientID: facebook.clientId,
    clientSecret: facebook.clientSecret,
    callbackURL: `//${( proxy && proxy.name ) || host.name}:${( proxy && proxy.port ) || host.port}/auth/facebook/redirect`,
    profileFields: [ "id", "displayName", "profile_pic", "gender", "email", "location", "about", "birthday" ]
};

passport.use( new FacebookStrategy( facebookAuthConfig, ( accessToken, refreshToken, profile, done ) => {
    return handleResult( { provider: "facebook", profile, done } );
} ) );

Anyone have any idea what I'm missing, why I'm seeing this error?

mbrand1 commented 6 years ago

I haven't looked at this in a while but my guess would be some of those fields you can't request just for authentication like birthday, gender, location, about. I would try without those.

ryexley commented 6 years ago

Ah, interesting...OK, I will give that a shot. Thanks for the idea.

ryexley commented 6 years ago

Well, that was at least what I needed. You pointed me in the right direction. I was using some keys there in my profileFields configuration that weren't valid. I ended up finding the reference page below that gave me a list of fields that I could actually get access to, and it gave me the properties I could use. Thanks giving me the clue I needed to get this figured out.

https://developers.facebook.com/docs/facebook-login/permissions