【问题标题】:Prevent error: "NotAuthenticated: Strategy jwt is not permitted"防止错误:“NotAuthenticated: Strategy jwt is not allowed”
【发布时间】:2019-07-21 09:50:49
【问题描述】:

我有 FeathersJS 作为 SocketIo 的 API Rest 服务器。对于身份验证,我使用 Firebase 并从客户端发送 fbToken,在服务器上检查并进行相应的身份验证。这是建立在 JWT 模型上的。 一切正常,除非我重新启动服务器。虽然我确实抓住了socket.on("reconnect_attempt", ()=>{... authentication function...} 并且它有效,但在重新验证之前我仍然收到错误:

error: NotAuthenticated: Strategy jwt is not permitted
    at new NotAuthenticated (...my-path...\back-end\node_modules\@feathersjs\errors\lib\index.js:93:17)
    at Object.<anonymous> (...my-path...\back-end\node_modules\@feathersjs\authentication\lib\hooks\authenticate.js:31:29)
    at Object.<anonymous> (...my-path...\kludi\back-end\node_modules\feathers-hooks-common\lib\common\iff-else.js:17:63)
    at ...my-path...\back-end\node_modules\feathers-hooks-common\node_modules\@feathersjs\commons\lib\hooks.js:164:73
    at processTicksAndRejections (internal/process/task_queues.js:89:5)

问题:

  1. 为什么会出现错误?确实 JWT 没有注册,我将方法命名为“firebaseAuth”,但是谁在使用 JWT 策略调用 auth 函数?在代码中找不到。

  2. 我应该忽略它还是解决它?即使没有修复错误,我也会感到不舒服。

【问题讨论】:

    标签: error-handling socket.io jwt feathersjs


    【解决方案1】:

    发现了问题,所以如果其他人看到这个帖子:

    确保您的新配置 socketIo 初始化之前,否则它将尝试使用JWT。 在我的情况下是:

    restApi.configure(auth(
            {
                header    : 'Authorization', // the default authorization header for REST
                prefix    : '', // if set will add a prefix to the header value. for example if prefix was 'JWT' then the header would be 'Authorization: JWT eyJ0eXAiOiJKV1QiLCJhbGciOi...'
                path      : '/..........', // the server-side authentication service path
                strategy  : 'firebase_strategy', // the name of the JWT authentication strategy
                entity    : 'users', // the entity you are authenticating (ie. a users)
                service   : 'users', // the service to look up the entity
                cookie    : 'token', // the name of the cookie to parse the JWT from when cookies are enabled server side
                storageKey: 'token', // the key to store the accessToken in localstorage or AsyncStorage on React Native
                storage   : localStorage // Passing a WebStorage-compatible object to enable automatic storage on the client.
            }
        ));
    

    const socket = io(... 紧随其后。问题解决了。

    【讨论】:

      猜你喜欢
      • 2017-10-12
      • 1970-01-01
      • 2021-12-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-27
      • 2021-02-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多