没有电子邮件的羽毛JS认证

时间:2018-02-15 11:43:43

标签: javascript express feathersjs feathers-authentication

我正在寻找一个身份验证系统,用户提交一个enpoint并在此端点生成一个jwt,我不知道如何实现这一点,我的客户端应用程序没有使用电子邮件地址或存储的信息,它是实际上是一个dApp。我只需要一个端点,如果这些值的处理顺利进行,将根据提供的种子短语和密码计算一个值(除非有人向端点发送垃圾,否则它几乎总是会这样)然后会发出一个jwt ..到目前为止羽毛cli的开箱即用功能意味着我需要使用本地策略并需要一个电子邮件地址,我无法在此找到任何演示......任何人都有任何指针?到目前为止,我的身份验证非常默认

const authentication = require('@feathersjs/authentication');
const jwt = require('@feathersjs/authentication-jwt');
const local = require('@feathersjs/authentication-local');


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

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

  // 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')
      ]
    }
  });
};

继续我的服务:

// Initializes the `aerAuth` service on path `/userauthendpoint`
const createService = require('feathers-memory');
const hooks = require('./userauthendpoint.hooks');

module.exports = function (app) {

  const paginate = app.get('paginate');

  const options = {
    name: 'userauthendpoint',
    paginate
  };

  // Initialize our service with any options it requires
  app.use('/userauthendpoint', createService(options) );

  // Get our initialized service so that we can register hooks and filters
  const service = app.service('userauthendpoint');

  service.hooks(hooks);
};

我对羽毛比较新,但不是建立auth系统(在PHP中)

1 个答案:

答案 0 :(得分:1)

Custom authentication strategy指南和feathers-authentication-custom插件可能允许您执行所需的操作。

这还取决于您希望如何实现它。您可以为每个服务使用自定义策略(如API密钥的情况,必须在每个请求的标头中发送)或在/authentication服务之前允许创建JWT(此处的问题)是的,它需要引用您不具备的数据库中存在的userId或其他entityId

最简单的方法是使用第一个选项和自定义标题(X-DAP-PASSWORD),它们看起来像这样:

const custom = require('feathers-authentication-custom');

app.configure(authentication(settings));
app.configure(custom((req, done) => {
  const password = req.headers['x-dap-password'];

  if(checkPassword(req.app.get('seedPassphrase'), password)) {
    // implement your own custom logic for loading and verifying the user
      done(null, user);
  } else {
    done(new Error('Invalid passphrase'));
  }
}));
相关问题