【问题标题】:Feathers JS authentication with no email没有电子邮件的羽毛 JS 身份验证
【发布时间】:2018-07-26 03:54:32
【问题描述】:

我正在寻找一个身份验证系统,其中用户提交到一个 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);
};

我对羽毛比较陌生,但对构建身份验证系统(在 PHP 中)不熟悉

【问题讨论】:

    标签: javascript express feathersjs feathers-authentication


    【解决方案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'));
      }
    }));
    

    【讨论】:

      猜你喜欢
      • 2019-08-07
      • 2018-05-12
      • 2021-10-05
      • 2017-08-10
      • 2019-01-17
      • 2021-12-08
      • 2018-02-10
      • 2015-03-21
      • 2023-03-18
      相关资源
      最近更新 更多