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

[feature] attach result of verifyClient to ws #1612

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.

None yet

2 participants