【问题标题】:400 BadRequest: Missing Credential feathersjs authentication-local400 BadRequest:缺少凭据 feathersjs authentication-local
【发布时间】:2018-07-10 21:14:24
【问题描述】:

我正在尝试使用 @feathersjs/authentication-local 对用户进行身份验证,虽然我提供了正确的用户名和密码,但我得到了以下响应

{
    "name": "BadRequest",
    "message": "Missing credentials",
    "code": 400,
    "className": "bad-request",
    "data": {
        "message": "Missing credentials"
    },
    "errors": {}
}

user 实体的 DB 属性是 username & password。我的配置如下

const settings = {
    secret: 'super&secret',
    usernameField: 'username',
    passwordField: 'password',
    entityUsernameField: 'username',
    entityPasswordField: 'password'
};

app.configure(authentication(settings))
        .configure(local());

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

我在请求正文中添加了"strategy": "local"。我错过了什么?请帮忙。

【问题讨论】:

    标签: node.js feathersjs feathers-authentication


    【解决方案1】:

    这通常发生在没有注册 Express bodyParser 中间件时。如feathers-chat 所示,它必须是set up before authentication

    【讨论】:

    • 实际上@Daff,我有 bodyParser 中间件并在身份验证挂钩之前注册。最近我使用羽毛生成器创建了成功的身份验证服务。我认为default.json 存在一些冲突。在我的服务和模式中,模型名称是users,但我必须在default.json中使用"entity": "user"
    【解决方案2】:

    Missing Credential feathersjs authentication-local,出现此错误的原因可能如下:

    1. 发送请求时缺少字段。通常,如果存在任何数据,则会引发错误,如 NotAuthenticated: Invalid login if the credentials are not correct.

    2. 在 default.json 中转义字段以避免引用系统环境变量。 Refer to this

    【讨论】:

      猜你喜欢
      • 2019-03-02
      • 1970-01-01
      • 1970-01-01
      • 2020-08-11
      • 1970-01-01
      • 2020-09-26
      • 2013-03-06
      • 2017-06-19
      • 2023-03-03
      相关资源
      最近更新 更多