feathersjs - 需要在feathersjs中添加多个usernameField

标签 feathersjs feathers-authentication

我是feathersjs新手,我正在使用它构建后端服务器,并且需要添加两种本地身份验证方式:通过电子邮件或移动设备 我已经将新的本地添加到 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

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

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

}

回复即将到来

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

有什么想法吗?

最佳答案

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

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

关于feathersjs - 需要在feathersjs中添加多个usernameField,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58172708/

相关文章:

javascript - Feathers.js API 中的用户权限

javascript - 将非用户字段添加到负载以用于 JWT token

feathersjs - 将自定义身份验证策略添加到 Feathers 应用程序的正确方法是什么?

javascript - 如何使用 ajax 休息调用正确填充数据表 JQuery

javascript - 将类转换为函数

typescript - 如何正确定义羽毛客户端的 Typescript 类型

javascript - 自定义 cli 生成的feathersjs 服务

node.js - VueFire vs Vue.js + Node.js vs Vue.js + Feathers 优缺点和差异