feathersjs-ecosystem / authentication-oauth2

[MOVED] OAuth 2 plugin for feathers-authentication
https://github.com/feathersjs/feathers
MIT License
26 stars 15 forks source link

How to authenticate token from Facebook on Feathers server #80

Closed achabill closed 6 years ago

achabill commented 6 years ago

I have logged in with react-native-fbsdk and gotten a token. I then want to authenticate on the server. Tried several things but don't work.

Server

const oauth2 = require('@feathersjs/authentication-oauth2');
const FacebookStrategy = require('passport-facebook');

module.exports = function (app) {
  const config = app.get('authentication');

  // Set up authentication with the secret
  app.configure(authentication(config));
  app.configure(jwt());

  app.configure(oauth2(Object.assign({
    name: 'facebook',
    Strategy: FacebookStrategy
  }, config.facebook)));

  // The `authentication` service is used to create a JWT.
  // The before `create` hook registers strategies that can be used
  // to create a new valid JWT (e.g. local or oauth2)
  app.service('authentication').hooks({
    before: {
      create: [
        authentication.hooks.authenticate(config.strategies)
      ],
      remove: [
        authentication.hooks.authenticate('jwt')
      ]
    }
  });
};

Client

Method 1

 feathersClient.authenticate({
    //When strategy is jwt, I get Error: Malformed JWT
    //All other strategies return not permited. e.g  *Strategy facebook is not permitted*
    //i've tried facebook, passport-facebook, facebook/access_token, passport-facebook/access_token
    strategy: "jwt", 
    accessToken: data.accessToken
})
.catch(){...}

Method2:


const options = {
  storageKey: 'feathers-jwt', 
  storage: AsyncStorage
}
feathersClient.configure(auth(options));
...
AsyncStorage.setItem("feathers-jwt", data.accessToken);
...

//Error: Invalid token specified: Cannot read property 'replace' of undefined
feathersClient.authenticate()
.then(){}
.catch(){}

What am I doing wrong? 
What's the correct way to authenticate Facebook with feathers.
achabill commented 6 years ago

No one?

daffl commented 6 years ago

You will probably have to use this module with https://github.com/drudge/passport-facebook-token and a different name as the strategy. Then

feathersClient.authenticate({
  strategy: 'facbeook-token',
  access_token: 'access token here'
});

Should get you a valid JWT.

daffl commented 6 years ago

Also see https://github.com/feathersjs/authentication/issues/561