python-websocketd
Python module for creating a http server which uses WebSockets.

◆ authenticate()

def websocketd.Httpd.authenticate (   self,
  connection 
)

Handle user authentication.

To use authentication, set auth_message to a static message or define it as a method which returns a message. The method is called with two arguments, connection and is_websocket. If it is or returns a True value (when cast to bool), authenticate will be called, which should return a bool. If it returns False, the connection will be rejected without notifying the program.

connection.data is a dict which contains the items 'user' and 'password', set to their given values. This dict may be changed by authenticate and is passed to the websocket. Apart from filling the initial contents, this module does not touch it. Note that connection.data is empty when auth_message is called. 'user' and 'password' will be overwritten before authenticate is called, but other items can be added at will.


NOTE REGARDING SECURITY


The module uses plain text authentication. Anyone capable of seeing the data can read the usernames and passwords. Therefore, if you want authentication, you will also want to use TLS to encrypt the connection.

Parameters
connectionThe connection to authenticate. Especially connection.data['user'] and connection.data['password'] are of interest.
Returns
True if the authentication succeeds, False if it does not.

Definition at line 1173 of file websocketd.py.