Skip to content

Conversation

@adrianhopebailie
Copy link
Contributor

This change attaches the result of verifyClient to the WebSocket instance that is created by the server.

This allows servers to provide an authentication function as the verifyClient server option and then subsequently have access to the authenticated client when handling the connection.

Example:

const WebSocket = require('ws');

const wss = new WebSocket.Server({ port: 8080, verifyClient: (info) => {
	const client = authenticateWebSocketHandshake(info.req)
	return client;
}});

wss.on('connection', function connection(ws) {

  // This client is the same value returned in the `verifyClient` callback above
  const client = ws.client

  ws.on('message', function incoming(message) {
    console.log('received from %s: %s', client, message);
  });

  ws.send('something');
});

@lpinca
Copy link
Member

lpinca commented Aug 1, 2019

See #377 (comment)

@lpinca
Copy link
Member

lpinca commented Aug 2, 2019

@adrianhopebailie sorry but I'm 👎 on this. I'm closing. Discussion can continue if needed.

@adrianhopebailie
Copy link
Contributor Author

Np. Wasn't aware of the history here. Have submitted #1613 to update some docs to save someone doing this too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants