コード例 #1
0
def TokenAuthMiddlewareStack(inner):
    return PrinterWSAuthMiddleWare(AuthMiddlewareStack(inner))
コード例 #2
0
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)])))
})
コード例 #3
0
ファイル: routing.py プロジェクト: netlgroup/cindy-realtime
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),
            ])),
    }))
コード例 #4
0
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)),
})
コード例 #5
0
ファイル: token_auth.py プロジェクト: HardLuckys/chatapp
        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))
コード例 #6
0
# 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
        )
    ),
})
コード例 #7
0
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))
})
コード例 #8
0
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.auth import AuthMiddlewareStack
import notes.routings

application = ProtocolTypeRouter({
    "websocket":
    AuthMiddlewareStack(URLRouter(notes.routings.websocket_urlpatterns))
})
コード例 #9
0
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)))
})
コード例 #10
0
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!'),
}
コード例 #11
0
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
                  )),
})
コード例 #12
0
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))
コード例 #14
0
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)),
})
コード例 #15
0
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()),
        ]), ),
})
コード例 #16
0
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),
            ]))),
})
コード例 #17
0
ファイル: routing.py プロジェクト: artemholovnia/sim
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),
            ])))
})
コード例 #18
0
ファイル: routing.py プロジェクト: souravlayek/wrinion
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),
                ]
            )
        )
    )
})
コード例 #19
0
ファイル: asgi.py プロジェクト: Demonic-lie/VideoChat_Django
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
        )
    ),
})
コード例 #20
0
ファイル: routing.py プロジェクト: sharif1302042/Aux_Login
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),
#         )
#     )
#
# })
コード例 #21
0
def TokenAuthMiddlewareStack(inner):
    return TokenAuthMiddleware(AuthMiddlewareStack(inner))
コード例 #22
0
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),
]
コード例 #23
0
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)),
})
コード例 #24
0
ファイル: routing.py プロジェクト: DICKQI/UTime_BackEnd
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))
})
コード例 #25
0
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)),
})
コード例 #26
0
# 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))}
)
コード例 #27
0
ファイル: routing.py プロジェクト: dvrpc/ghg-calculator
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())),
})
コード例 #28
0
# 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)),
})
コード例 #29
0
ファイル: asgi.py プロジェクト: jerrypeng02/Hikerrank
"""
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)),
})
コード例 #30
0
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
    })
})