Skip to content

Commit 83c652d

Browse files
authored
Merge pull request #11 from vporton/master
added cookie-based authentication
2 parents 2ee4518 + 2b51eab commit 83c652d

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

README.rst

+14
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,20 @@ The ``user_db.txt`` is a text file with one entry per line::
6060
user_id:username:user_token
6161

6262

63+
Generating messages programmatically
64+
####################################
65+
66+
To pass a message to a WebSocket client through RabbitMQ you can use `pika` Python module::
67+
68+
connection = pika.BlockingConnection()
69+
channel = connection.channel()
70+
channel.basic_publish(exchange='pushpull.ws',
71+
# routing_key='pushpull.ws', # broadcast to all open WebSockets
72+
routing_key=('pushpull.ws.%d' % user_id),
73+
body='{"test": "Test"}')
74+
connection.close()
75+
76+
6377

6478
Build docker image
6579
##################

pushpull/config.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
WEBSOCKET_URL = os.environ.get('PUSHPULL_WEBSOCKET_URL', '')
66
BROKER_URL = os.environ.get('PUSHPULL_BROKER_URL', '')
77
CORS_ALLOWED_ORIGINS = os.environ.get('PUSHPULL_CORS_ALLOWED_ORIGINS', '')
8+
AUTH_COOKIE = os.environ.get('PUSHPULL_AUTH_COOKIE', '')
89

910

1011
def get_host_port():

pushpull/websocket/gateway.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717

1818

1919
async def websocket_rabbitmq_gateway(request):
20-
authorization = decode_auth_querystring_param(request.GET)
20+
if config.AUTH_COOKIE != '':
21+
authorization = request.cookies.get(config.AUTH_COOKIE);
22+
else:
23+
authorization = decode_auth_querystring_param(request.GET)
2124
try:
2225
# TODO: reuse amqp channel and maybe share it with the Exchanger
2326
user_info = await auth.get_user_info(authorization)

0 commit comments

Comments
 (0)