【问题标题】:hook.params.user does not exist after successful feathers js authentication成功羽毛js认证后hook.params.user不存在
【发布时间】:2017-11-05 21:42:21
【问题描述】:

如果你查看官方的羽毛身份验证插件的默认选项,它说在 hook.params.user 中应该有一个用户对象(在实体选项下)

https://github.com/feathersjs/feathers-authentication

{
  path: '/authentication', // the authentication service path
  header: 'Authorization', // the header to use when using JWT auth
  **entity: 'user', // the entity that will be added to the request, socket, and hook.params. (ie. req.user, socket.user, hook.params.user)**
  service: 'users', // the service to look up the entity
  passReqToCallback: true, // whether the request object should be passed to the strategies `verify` function
  session: false, // whether to use sessions
  cookie: {
    enabled: false, // whether the cookie should be enabled
    name: 'feathers-jwt', // the cookie name
    httpOnly: false, // whether the cookie should not be available to client side JavaScript
    secure: true // whether cookies should only be available over HTTPS
  },
  jwt: {
    header: { typ: 'access' }, // by default is an access token but can be any type
    audience: 'https://yourdomain.com', // The resource server where the token is processed
    subject: 'anonymous', // Typically the entity id associated with the JWT
    issuer: 'feathers', // The issuing server, application or resource
    algorithm: 'HS256', // the algorithm to use
    expiresIn: '1d' // the access token expiry
  }
}

我的身份验证成功,并且我在 window.localStorage 中存储了一个 jwt 令牌。我只是不知道如何添加以使 hook.params.user 对象出现。我需要在服务器端设置一些东西吗?我当前的身份验证流程只是文档设置的示例。

我目前的怀疑是这是遗留信息,因为新文档没有提到 hook.params.user 对象可用,我认为它只是使用钩子来插入用户 ID。

https://docs.feathersjs.com/api/authentication/client.html

如果是这种情况,有没有办法只获取当前登录用户的用户 id 而无需使用钩子添加它?

谢谢

【问题讨论】:

    标签: node.js authentication feathersjs


    【解决方案1】:

    它仍在添加中,但您必须使用存储中的令牌验证套接字连接或 HTTP 请求。这通常通过在进行任何其他服务调用之前 在客户端上调用client.reAuthenticate()(不带参数)来完成。要查看它的实际效果,请查看JS chat frontend

    【讨论】:

    • 啊完美。我没有意识到每次打开应用程序时都必须调用 app.authenticate 。我看到现在添加了用户对象。
    • Vanilla JS Chat 前端的链接已损坏。
    猜你喜欢
    • 2022-06-27
    • 2018-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-07
    • 2018-07-26
    • 2021-06-12
    • 2012-11-11
    相关资源
    最近更新 更多