def TokenAuthMiddlewareStack(inner): return PrinterWSAuthMiddleWare(AuthMiddlewareStack(inner))
from django.conf.urls import url from channels.routing import ProtocolTypeRouter, URLRouter from channels.auth import AuthMiddlewareStack from channels.security.websocket import AllowedHostsOriginValidator, OriginValidator from channels.routing import ProtocolTypeRouter from chat.consumers import ChatConsumer application = ProtocolTypeRouter({ 'websocket': AllowedHostsOriginValidator( AuthMiddlewareStack(URLRouter([url("ws/chat/room/", ChatConsumer)]))) })
from channels.auth import AuthMiddlewareStack from channels.routing import ProtocolTypeRouter, URLRouter from channels.staticfiles import StaticFilesWrapper from django.conf.urls import url from .consumers import GraphqlSubcriptionConsumer, MainConsumer application = StaticFilesWrapper( ProtocolTypeRouter({ "websocket": AuthMiddlewareStack( URLRouter([ url("^ws/$", GraphqlSubcriptionConsumer), url("^direct/$", MainConsumer), ])), }))
import os from channels.routing import ProtocolTypeRouter, URLRouter from channels.auth import AuthMiddlewareStack import chat.routing os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ChatProject.settings') application = ProtocolTypeRouter({ 'websocket': AuthMiddlewareStack(URLRouter(chat.routing.websocket_urlpatterns)), })
token = Token.objects.get(key=token) return token.user except Token.DoesNotExist: return AnonymousUser() class TokenAuthMiddleware: def __init__(self, inner): self.inner = inner def __call__(self, scope): return TokenAuthMiddlewareInstance(scope, self) class TokenAuthMiddlewareInstance: def __init__(self, scope, middleware): self.middleware = middleware self.scope = dict(scope) self.inner = self.middleware.inner async def __call__(self, receive, send): token = parse_qs(self.scope["query_string"].decode("utf8"))["token"][0] self.scope['user'] = await get_user(token) inner = self.inner(self.scope) return await inner(receive, send) TokenAuthMiddlewareStack = lambda inner: TokenAuthMiddleware(AuthMiddlewareStack(inner))
# mysite/routing.py from channels.auth import AuthMiddlewareStack from channels.routing import ProtocolTypeRouter, URLRouter import main.routing application = ProtocolTypeRouter({ 'websocket': AuthMiddlewareStack( URLRouter( main.routing.websocket_urlpatterns ) ), })
import os from channels.auth import AuthMiddlewareStack from channels.routing import ProtocolTypeRouter, URLRouter from django.core.asgi import get_asgi_application import monitor.routing os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cercainteligente.settings") application = ProtocolTypeRouter({ 'http': get_asgi_application(), 'websocket': AuthMiddlewareStack(URLRouter(monitor.routing.websocket_urlpatterns)) })
from channels.routing import ProtocolTypeRouter, URLRouter from channels.auth import AuthMiddlewareStack import notes.routings application = ProtocolTypeRouter({ "websocket": AuthMiddlewareStack(URLRouter(notes.routings.websocket_urlpatterns)) })
from channels.auth import AuthMiddlewareStack from channels.routing import ProtocolTypeRouter, URLRouter from channels.security.websocket import AllowedHostsOriginValidator from openwisp_notifications.websockets.routing import get_routes from openwisp_controller.geo.channels.routing import geo_routes application = ProtocolTypeRouter({ 'websocket': AllowedHostsOriginValidator( AuthMiddlewareStack(URLRouter(get_routes() + geo_routes))) })
from channels.auth import AuthMiddlewareStack from channels.routing import ProtocolTypeRouter, URLRouter import chat.routing import webui_list.routing application = ProtocolTypeRouter({ # (http->django views is added by default) 'websocket': AuthMiddlewareStack( URLRouter( chat.routing.websocket_urlpatterns + webui_list.routing.websocket_urlpatterns ) ), }) channel_routing = { # You can name your channel anything you want, you probably see 'websocket.*' in most tutorials. 'your_channel_name': lambda x: print('Channel Triggered Event!'), }
import os from channels.auth import AuthMiddlewareStack from channels.routing import ProtocolTypeRouter, URLRouter from django.core.asgi import get_asgi_application os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cranch.settings') application = ProtocolTypeRouter({ "http": get_asgi_application(), "websocket": AuthMiddlewareStack( URLRouter([] # TODO: replace with routing.websocket_urlpatterns )), })
from django.conf.urls import url from channels.routing import ProtocolTypeRouter, URLRouter from channels.auth import AuthMiddlewareStack from channels.security.websocket import AllowedHostsOriginValidator, OriginValidator from web_mpl.consumers import MplConsumer application = ProtocolTypeRouter({ # Websocket chat handler 'websocket': AllowedHostsOriginValidator( AuthMiddlewareStack( URLRouter([ url(r"^example/(?P<fig_id>[0-9]+)/$", MplConsumer, name='example') # url(r"^messages/(?P<username>[\w.@+-]+)/$", ChatConsumer) ])), ) })
from graphql_jwt import utils class TokenAuthMiddleware: """ Middleware to handle user that is connecting to websocket """ def __init__(self, inner): self.inner = inner def __call__(self, scope): """ Return user(or AnonymousUser) that tries to connect to websockets """ headers = dict(scope['headers']) user = None if b'cookie' in headers: cookie = headers[b'cookie'].decode("utf-8") result = re.search(r'authorization=[\w.-]+', cookie) if result: token = result.group(0).split('=')[1] email = utils.jwt_decode(token)['email'] user = get_user_model().objects.get(email=email) if user: scope['user'] = user else: scope['user'] = AnonymousUser() return self.inner(scope) TokenAuthMiddlewareStack = lambda inner: TokenAuthMiddleware( AuthMiddlewareStack(inner))
from channels.auth import AuthMiddlewareStack from channels.routing import ProtocolTypeRouter, URLRouter import team_management.routing application = ProtocolTypeRouter({ # Empty for now (http->django views is added by default) 'websocket': AuthMiddlewareStack( URLRouter(team_management.routing.websocket_urlpatterns)), })
ASGI config for bop project. It exposes the ASGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/ """ import os from channels.auth import AuthMiddlewareStack from channels.routing import ProtocolTypeRouter, URLRouter from django.core.asgi import get_asgi_application from django.urls import path from apps.campaigns.consumer import CampaignConsumer from apps.notifications.consumer import NotificationConsumer os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'bop.settings') application = ProtocolTypeRouter({ "http": get_asgi_application(), "websocket": AuthMiddlewareStack( URLRouter([ path('ws/notifications/<int:user_id>/', NotificationConsumer.as_asgi()), path('ws/campaigns/<int:user_id>/', CampaignConsumer.as_asgi()), ]), ), })
from channels.auth import AuthMiddlewareStack from channels.routing import ProtocolTypeRouter, URLRouter from channels.security.websocket import AllowedHostsOriginValidator from django.urls import path, re_path from chat.consumers import ChatConsumer from public_chat.consumers import PublicChatConsumer from notification.consumers import NotificationConsumer application = ProtocolTypeRouter({ 'websocket': AllowedHostsOriginValidator( AuthMiddlewareStack( URLRouter([ path('', NotificationConsumer), path('chat/<room_id>/', ChatConsumer), path('public_chat/<room_id>/', PublicChatConsumer), ]))), })
from channels.routing import ProtocolTypeRouter, URLRouter from channels.auth import AuthMiddlewareStack from channels.security.websocket import AllowedHostsOriginValidator from django.conf.urls import url from ari_controller.consumers import AriChannelsConsumer, ChannelsConsumer application = ProtocolTypeRouter({ # Empty for now (http->django views is added by default) 'websocket': AllowedHostsOriginValidator( AuthMiddlewareStack( URLRouter([ url(r'^ari_controller/channels/$', ChannelsConsumer), #url(r'^chat/$', ChatConsumer), ]))) })
from django.conf.urls import url from channels.routing import ProtocolTypeRouter, URLRouter from channels.auth import AuthMiddlewareStack from channels.security.websocket import AllowedHostsOriginValidator, OriginValidator from chat.consumers import ChatConsumer application = ProtocolTypeRouter({ # (http->django views is added by default) 'websocket': AllowedHostsOriginValidator( AuthMiddlewareStack( URLRouter( [ url(r"^messages/(?P<username>[\w.@+-]+)", ChatConsumer), ] ) ) ) })
import os from channels.auth import AuthMiddlewareStack from channels.routing import ProtocolTypeRouter, URLRouter from django.core.asgi import get_asgi_application import koru.routing os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") application = ProtocolTypeRouter({ "http": get_asgi_application(), "websocket": AuthMiddlewareStack( URLRouter( koru.routing.websocket_urlpatterns ) ), })
from channels.auth import AuthMiddlewareStack from channels.routing import ProtocolTypeRouter, URLRouter import whats_app_login.routing application = ProtocolTypeRouter({ # (http->django views is added by default) 'websocket': AuthMiddlewareStack( URLRouter(whats_app_login.routing.websocket_urlpatterns)), }) # application = ProtocolTypeRouter({ # # (http->django views is added by default) # 'websocket': AllowedHostsOriginValidator( # AuthMiddlewareStack( # url(r"^api/v1/home$",OTPConsumer), # ) # ) # # })
def TokenAuthMiddlewareStack(inner): return TokenAuthMiddleware(AuthMiddlewareStack(inner))
from api import consumers from django.conf.urls import url from channels.routing import ProtocolTypeRouter, URLRouter from channels.auth import AuthMiddlewareStack application = ProtocolTypeRouter({ # (http->django views is added by default) 'websocket': AuthMiddlewareStack(URLRouter(websocket_urlpatterns)), }) websocket_urlpatterns = [ url(r'^ws/chat/(?P<room_name>[^/]+)/$', consumers.ChatConsumer), ]
from channels.auth import AuthMiddlewareStack from channels.routing import ProtocolTypeRouter, URLRouter import IBIS_creator.routing application = ProtocolTypeRouter({ # Empty for now (http->django views is added by default) 'websocket': AuthMiddlewareStack(URLRouter(IBIS_creator.routing.websocket_urlpatterns)), })
from channels.auth import AuthMiddlewareStack from channels.routing import ProtocolTypeRouter, URLRouter import App.ChatRoom.routing application = ProtocolTypeRouter({ 'websocket': AuthMiddlewareStack(URLRouter(App.ChatRoom.routing.websocket_patterns)) })
from channels.auth import AuthMiddlewareStack from channels.routing import ProtocolTypeRouter, URLRouter import foodfficient.routing application = ProtocolTypeRouter({ # (http->django views is added by default) 'websocket': AuthMiddlewareStack(URLRouter(foodfficient.routing.websocket_urlpatterns)), })
# from channels.routing import route # from otree.channels.routing import channel_routing # from cartelgame.consumers import ws_message, ws_add # channel_routing += [ # route("websocket.connect", ws_add, path=r"^/custom/report"), # route("websocket.receive", ws_message, path=r"^/custom/report"), # ] from channels.routing import route # from otree.channels.routing import channel_routing from channels.routing import ProtocolTypeRouter, URLRouter from channels.auth import AuthMiddlewareStack from django.conf.urls import url from cartelgame.consumers import ws_message, ws_add websocket_routes = [ # url(r"^custom/report/", ws_add), # url(r"^custom/report/", ws_message), route("websocket.connect", ws_add, path=r"^/custom/report"), route("websocket.receive", ws_message, path=r"^/custom/report"), ] application = ProtocolTypeRouter( {"websocket": AuthMiddlewareStack(URLRouter(websocket_routes))} )
from channels.auth import AuthMiddlewareStack from channels.routing import ProtocolTypeRouter, URLRouter from django.apps import apps bokeh_app_config = apps.get_app_config("bokeh.server.django") application = ProtocolTypeRouter({ "websocket": AuthMiddlewareStack( URLRouter(bokeh_app_config.routes.get_websocket_urlpatterns())), "http": AuthMiddlewareStack( URLRouter(bokeh_app_config.routes.get_http_urlpatterns())), })
# mysite/routing.py from channels.auth import AuthMiddlewareStack from channels.routing import ProtocolTypeRouter, URLRouter import issue_tracker.routing application = ProtocolTypeRouter({ # (http->django views is added by default) 'websocket': AuthMiddlewareStack(URLRouter( issue_tracker.routing.websocket_urlpatterns)), })
""" ASGI config for webapps project. It exposes the ASGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/ """ import os from channels.auth import AuthMiddlewareStack from channels.routing import ProtocolTypeRouter, URLRouter from django.core.asgi import get_asgi_application import hikerrank.routing os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'webapps.settings') # application = get_asgi_application() application = ProtocolTypeRouter({ "http": get_asgi_application(), "websocket": AuthMiddlewareStack(URLRouter(hikerrank.routing.websocket_urlpatterns)), })
from django.conf.urls import url from channels.routing import ProtocolTypeRouter, URLRouter, ChannelNameRouter from channels.auth import AuthMiddlewareStack from channels.security.websocket import AllowedHostsOriginValidator, OriginValidator from smessage.consumers import ChatConsumer, TaskConsumer application = ProtocolTypeRouter({ # Websocket chat handler 'websocket': AllowedHostsOriginValidator( AuthMiddlewareStack( URLRouter( [ #url(r"chat/", ChatConsumer, name='chat') url(r"messages/(?P<username>[\w.@+-]+)/$", ChatConsumer, name='chat') ] ) ), ), 'channel': ChannelNameRouter({ 'task': TaskConsumer }) })