Auth-module: Add facebook scheme

Created on 19 Feb 2018  路  3Comments  路  Source: nuxt-community/auth-module

original request by @Syffs

I've tried adding a facebook scheme, not sure I got it right though...
SSR is not working and I'm not sure how accessToken is supposed to be sent back to the server. Any insight?
I also though about implementing this without SDK not sure what is the preferred way..

This feature request is available on Nuxt.js community (#c55)
enhancement scheme

Most helpful comment

Another question: Have you though about a specific way of sending accessToken or code to a specific endpoint in the callback?
Usually after social authentication, accessToken or code is sent to your webserver for long-lived-access-token generation, database provisioning and later access.

I see that Oauth2Scheme._handleCallback only pushes authorization code to access_token_endpoint when this.options.response_type === 'code', but Facebook API allows response_type=code%20token (I don't know about other providers)

All 3 comments

Thanks, Facebook provider using oauth2 scheme works perfectly.

It would be great to be able to adjust hardcoded providers parameters (mainly scope and userinfo_endpoint) through strategies into nuxt.config.js. I've tried setting these setups unsuccessfully:

  • Add custom endpoint & scope to existing facebook strategy
      facebook: {
        client_id: '1671464192946675',
        userinfo_endpoint: 'https://graph.facebook.com/v2.12/me?fields=about,name,picture{url},email,birthday,friends',
        scope: ['public_profile', 'email', 'user_friends', 'user_birthday']
      },

These changes are needed for this to work

  • Custom strategy as in here:
      fb: {
        _scheme: 'oauth2',
        client_id: '1671464192946675',
        authorization_endpoint: 'https://facebook.com/v2.12/dialog/oauth',
        userinfo_endpoint: 'https://graph.facebook.com/v2.12/me?fields=about,name,picture{url},email,birthday,friends',
        scope: ['public_profile', 'email', 'user_friends', 'user_birthday']
      },

edit: Actually, 2nd option seems to work even though 1st one would be more elegant
I was getting some strange error at first, but it must have been due to previous cookie:

{ TypeError: Cannot read property 'mounted' of undefined
    at Auth.mounted (.nuxt/auth/auth.js:245:0)
    at Auth.init (.nuxt/auth/auth.js:39:0)
    at module.exports.__webpack_exports__.a (.nuxt/auth/plugin.js:33:0)
    at createApp (.nuxt/index.js:156:0)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7) statusCode: 500, name: 'TypeError' }

Another question: Have you though about a specific way of sending accessToken or code to a specific endpoint in the callback?
Usually after social authentication, accessToken or code is sent to your webserver for long-lived-access-token generation, database provisioning and later access.

I see that Oauth2Scheme._handleCallback only pushes authorization code to access_token_endpoint when this.options.response_type === 'code', but Facebook API allows response_type=code%20token (I don't know about other providers)

The Facebook scheme is _basically_ working. I would let enhancement to be done in new issues and PRs.

Was this page helpful?
0 / 5 - 0 ratings