【问题标题】:Need to add more than usernameField in feathersjs需要在feathersjs中添加多于usernameField
【发布时间】:2020-01-30 00:46:59
【问题描述】:

我是 feathersjs 的新手,我正在使用它构建后端服务器,并且需要添加 2 种本地身份验证方式,通过电子邮件或移动 我已经在config/default.json 中添加了新的本地代码,如下所示

"local-mobile": {
      "usernameField": "mobile",
      "passwordField": "password"
    },

这是我的 authentication.js 文件

const { AuthenticationService, JWTStrategy } = require('@feathersjs/authentication');
const { LocalStrategy } = require('@feathersjs/authentication-local');
const { expressOauth } = require('@feathersjs/authentication-oauth');

module.exports = app => {
  const authentication = new AuthenticationService(app);

  authentication.register('jwt', new JWTStrategy());
  authentication.register('local', new LocalStrategy());
  authentication.register('local-mobile', new LocalStrategy());

  app.use('/authentication', authentication);
  app.configure(expressOauth());
};

src/authentication

但是当我使用带有以下正文的邮递员向身份验证端点发送发布请求时

{
    "strategy":"local-mobile",
    "mobile":".......",
    "password":"........"

}

响应来了

{
    "name": "NotAuthenticated",
    "message": "Invalid authentication information",
    "code": 401,
    "className": "not-authenticated",
    "errors": {}
}

有什么想法吗?

【问题讨论】:

    标签: feathersjs feathers-authentication


    【解决方案1】:

    如果要允许通过authenticate 端点进行身份验证,还必须将策略添加到config/default.json 中的authStrategies configuration setting (feathers-chat example):

    {
      "authentication": {    
        // ...
        "authStrategies": [
          "jwt",
          "local",
          "local-mobile",
        ]
      }
      // ...
    }
    

    【讨论】:

    • @Daff 我在添加这样的策略时犯了同样的错误。我想知道在这种情况下是否有办法提供更好的错误消息或诊断?我花了一些源代码级别的挖掘来找到我的疏忽。
    • 改进github.com/feathersjs/feathers/blob/… 中的错误消息相当容易,因此欢迎提出问题或 PR 来跟踪此问题。
    • PR 在github.com/feathersjs/feathers/pull/1600 中有更好的错误消息
    猜你喜欢
    • 2023-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多