julianlam / nodebb-plugin-sso-facebook

Single Sign-On Plugin for NodeBB
BSD 2-Clause "Simplified" License
19 stars 19 forks source link

without `displayName` in profile fields, error emits + auth fails #24

Closed sarim closed 8 years ago

sarim commented 8 years ago

Phew, took me one hour to finally nail the issue. The frontend shows a oauth error,

/auth/facebook/callback
This authorization code has been used.

And i spend the whole hour trying to nail the oauth error, but actually it throws two error in log.

23/11 10:37 [28114] - error: TypeError: Cannot call method 'trim' of undefined
    at Object.User.create (/var/www/pcwrforum/nodebb/src/user/create.js:17:33)
    at /var/www/pcwrforum/nodebb/node_modules/nodebb-plugin-sso-facebook/library.js:161:12
    at try_callback (/var/www/pcwrforum/nodebb/node_modules/redis/index.js:573:9)
................
................
[cluster] Child Process (28114) has exited (code: 1, signal: null)

Another one

23/11 10:37 [28116] - error: /auth/facebook/callback
 FacebookTokenError: This authorization code has been used.
...............

without displayName in requested profile fields in facebook request, name remains undefined, thus the error related to trim. For some reason this causes the request to re-execute and thus the causing the "code already used" error from facebook auth.

adding displayName to profileFields solves both errors. oAuth works properly and new user is created.

julianlam commented 8 years ago

Good work! Thank you for your attention to detail :smile:

julianlam commented 8 years ago

v1.1.5

julianlam commented 8 years ago

What's odd is that it worked before... did the api change?

sarim commented 8 years ago

Ah, i think i know the cause for request re-execute. First node process did quit due to error, and i guess nginx passed the request to second process, which resulted in facebook auth code reuse :P

About Facebook api, It did change. They removed username, made userid app specific etc... I guess they changed other things too. Read the changelog for v2.0 to v2.3.

Now my users are complaining their picture aren't being fetched from facebook. I'll open another issue for that.

julianlam commented 8 years ago

If you keep this work up, I just might make you maintainer for this SSO plugin :laughing: