Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown authentication strategy #285

Closed
jaulz opened this issue Jul 25, 2019 · 3 comments
Closed

Unknown authentication strategy #285

jaulz opened this issue Jul 25, 2019 · 3 comments
Assignees
Labels
bug
Milestone

Comments

@jaulz
Copy link
Contributor

@jaulz jaulz commented Jul 25, 2019

If we set the mode to optional, the very first auth reverification after the initial connection will fail:

  error: AssertionError [ERR_ASSERTION]: Unknown authentication strategy: 
      at module.exports.internals.Auth.verify (/.../node_modules/@hapi/hapi/lib/auth.js:114:14)
      at module.exports.internals.Socket.internals.Socket._verifyAuth (/.../node_modules/@hapi/nes/lib/socket.js:617:32)
      at module.exports.internals.Socket.internals.Socket._lifecycle (/.../node_modules/@hapi/nes/lib/socket.js:280:16)
      at module.exports.internals.Socket.internals.Socket._onMessage (/.../node_modules/@hapi/nes/lib/socket.js:246:48)
      at WebSocket.<anonymous> (/.../node_modules/@hapi/nes/lib/socket.js:53:46)
      at WebSocket.emit (events.js:203:13)
      at Receiver.receiverOnMessage (/.../node_modules/ws/lib/websocket.js:789:20)
      at Receiver.emit (events.js:203:13)
      at Receiver.dataMessage (/.../node_modules/ws/lib/receiver.js:422:14)
      at Receiver.getData (/.../node_modules/ws/lib/receiver.js:352:17)
      at Receiver.startLoop (/.../node_modules/ws/lib/receiver.js:138:22)
      at Receiver._write (/.../node_modules/ws/lib/receiver.js:74:10)
      at doWrite (_stream_writable.js:417:12)
      at writeOrBuffer (_stream_writable.js:401:5)
      at Receiver.Writable.write (_stream_writable.js:301:11)
      at Socket.socketOnData (/.../node_modules/ws/lib/websocket.js:864:35)
      at Socket.emit (events.js:203:13)
      at addChunk (_stream_readable.js:294:12)
      at readableAddChunk (_stream_readable.js:275:11)
      at Socket.Readable.push (_stream_readable.js:210:10)
      at TCP.onStreamRead (internal/stream_base_commons.js:166:17)

I tracked it down and these line cause the issues:

        const strategy = this._strategies[auth.strategy];
        Hoek.assert(strategy, 'Unknown authentication strategy:', auth.strategy);

this._strategies contains my defined strategies but auth.strategy is empty and thus it fails.

This is my code for Nes in general:

    await this.server.register({
      plugin: Nes,
      options: {
        auth: {
          type: 'direct',
          endpoint: '/_api/socket',
          password: keys[0],
          route: {
            mode: 'optional',
            strategy: 'jwt',
          },
        },
        origin,
      },
    })
@hueniverse hueniverse self-assigned this Sep 12, 2019
@hueniverse hueniverse added the bug label Sep 12, 2019
@hueniverse hueniverse added this to the 11.2.2 milestone Sep 12, 2019
@hueniverse

This comment has been minimized.

Copy link
Member

@hueniverse hueniverse commented Sep 12, 2019

Why are you setting auth mode on the authentication endpoint?! I am aware it is possible but I don't understand the use case. The auth endpoint is used only for auth. There is no purpose to it other than that. If you want to set optional auth, you do that on the actual endpoints nes is serving.

Am I missing something?

@jaulz

This comment has been minimized.

Copy link
Contributor Author

@jaulz jaulz commented Sep 16, 2019

@hueniverse my use case is the following: any user should be able to connect in order to receive updates but once a user signs in he will reauthenticate and receive personal updates.

@hueniverse

This comment has been minimized.

Copy link
Member

@hueniverse hueniverse commented Sep 16, 2019

That doesn't mean you want the authentication endpoint to have optional authentication. If you simply omit auth from the connection, you will have optional authentication.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.