Skip to content

Commit

Permalink
Merge pull request #82 from eagle21st/master
Browse files Browse the repository at this point in the history
Add flexibility to handle customized authentication
  • Loading branch information
jrief committed Mar 4, 2015
2 parents 437dbd8 + fad5ba7 commit 534bd5f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ws4redis/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,9 @@
database!
"""
WS4REDIS_ALLOWED_CHANNELS = getattr(settings, 'WS4REDIS_ALLOWED_CHANNELS', None)

"""
If set, this callback function is called instead of the default process_request function in WebsocketWSGIServer.
This function can be used to enforce custom authentication flow. i.e. JWT
"""
WS4REDIS_PROCESS_REQUEST = getattr(settings, 'WS4REDIS_PROCESS_REQUEST', None)
5 changes: 4 additions & 1 deletion ws4redis/wsgi_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ def __call__(self, environ, start_response):
try:
self.assure_protocol_requirements(environ)
request = WSGIRequest(environ)
self.process_request(request)
if callable(private_settings.WS4REDIS_PROCESS_REQUEST):
private_settings.WS4REDIS_PROCESS_REQUEST(request)
else:
self.process_request(request)
channels, echo_message = self.process_subscriptions(request)
if callable(private_settings.WS4REDIS_ALLOWED_CHANNELS):
channels = list(private_settings.WS4REDIS_ALLOWED_CHANNELS(request, channels))
Expand Down

0 comments on commit 534bd5f

Please sign in to comment.