无法使用羽毛认证进行认证

时间:2019-10-04 07:47:25

标签: node.js authentication feathersjs feathers-authentication

我创建了Feathers js应用,然后使用feather generate authentication

添加了身份验证

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

然后我将以下代码添加到 app.js

const authentication = require('./authentication');
app.configure(authentication);

default.json 看起来像这样

"authentication": {
    "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"
    }
  }

当我从邮递员向localhost:3030/users的用户服务发送发帖请求时,创建了新用户,但是当我尝试使用有效载荷从邮递员向localhost:3030/authentication的发帖请求

{"strategy":"local","email":"user","password":"pass"}

我得到以下回应

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

一切看起来不错,但我无法正常工作,我一直在关注tutorial,请问有什么可以帮助我的吗?预先感谢。

0 个答案:

没有答案