首页 > 解决方案 > 无法使用羽毛身份验证进行身份验证

问题描述

我创建了羽毛 js 应用程序,然后使用添加了身份验证feather generate 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": {}
}

一切看起来都很好,但我无法让它工作,我一直在关注这个教程,可以帮助我吗?提前致谢。

标签: node.jsauthenticationfeathersjsfeathers-authentication

解决方案


推荐阅读