Feathersjs-多个身份验证端点

问题描述 投票:1回答:1

我有来自两个不同客户端(角度客户端和node.js feathers客户端)的传入连接,我希望他们使用两个不同的身份验证端点(基于两个单独表中的数据)。一种应该针对/ users服务进行身份验证,另一种针对/ users2服务进行身份验证。

如何实现?

这是一个认证端点的工作方式:

// default.json
"authentication": {
    "secret": "<secret>",
    "strategies": [
      "jwt",
      "local"
    ],
    "path": "/authentication",
    "service": "users",
    "jwt": {
      "header": {
        "typ": "access"
      },
      "audience": "https://yourdomain.com",
      "subject": "anonymous",
      "issuer": "feathers",
      "algorithm": "HS256",
      "expiresIn": "1d"
    },
    "local": {
      "entity": "user",
      "usernameField": "email",
      "passwordField": "password"
    }
  }

// authentication.js
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');

  app.configure(authentication(config));
  app.configure(jwt());
  app.configure(local());

  app.service('authentication').hooks({
    before: {
      create: [
        authentication.hooks.authenticate(config.strategies),
      ],
      remove: [
        authentication.hooks.authenticate('jwt')
      ]
    }
  });

};

谢谢!

feathersjs feathers-authentication
1个回答
1
投票
不确定过去是否可能,但是使用当前的FeathersJS(4.5.0),您可以创建具有不同配置的多个AuthenticationService实例:
© www.soinside.com 2019 - 2024. All rights reserved.