Skip to content

403 error (failing WebSocket opening handshake ('Access denied')) #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Mr-Perfection opened this issue Jan 21, 2022 · 0 comments
Closed

Comments

@Mr-Perfection
Copy link

  • GraphQL AioWS version: graphql_ws 0.4.4
  • Python version: Python 3.8.10
  • Operating System: Ubuntu

Description

I'm running Daphnie with asgi.py but when I try to test it with wscat it gives 403 (access denied) error in logs in daphne servers.

What I Did

asgi.py

import os

from channels.routing import ProtocolTypeRouter, URLRouter
from channels.security.websocket import OriginValidator


os.environ.setdefault("DJANGO_SETTINGS_MODULE", "company.settings.base")
from graphql_ws.django.routing import websocket_urlpatterns

# This configures route to /subscriptions.
# https://github.com/graphql-python/graphql-ws/blob/474f733761c04f39ccd9367190b5a85a5033fc2c/graphql_ws/django/routing.py#L20

application = ProtocolTypeRouter({
    "websocket": URLRouter(websocket_urlpatterns),
})

settings.py

# ...
INSTALLED_APPS = (
# ...
    'channels',
    "graphql_ws.django",
    'graphene_django',
# ...
)


GRAPHENE = {
    'SCHEMA': 'schema.schema', 
    'MIDDLEWARE': [
        'graphql_jwt.middleware.JSONWebTokenMiddleware',
    ],
    # https://docs.graphene-python.org/projects/django/en/latest/subscriptions/#subscriptions
    "SUBSCRIPTION_PATH": "/subscriptions",
}

ASGI_APPLICATION = 'app.asgi.application'

# ...

Then I run daphne -p 8001 app.asgi:application -v 2
In other console, I ruh websocket commands with wscat -c ws://localhost:8001/subscriptions
it was giving me the logs (errors)

2022-01-21 12:23:10,555 INFO     Listening on TCP address 127.0.0.1:8001
127.0.0.1:54400 - - [21/Jan/2022:12:23:16] "WSCONNECTING /subscriptions" - -
2022-01-21 12:23:16,476 DEBUG    Upgraded connection ['127.0.0.1', 54400] to WebSocket
2022-01-21 12:23:16,476 INFO     failing WebSocket opening handshake ('Access denied')
2022-01-21 12:23:16,477 WARNING  dropping connection to peer tcp4:127.0.0.1:54400 with abort=False: Access denied
2022-01-21 12:23:16,477 DEBUG    WebSocket ['127.0.0.1', 54400] rejected by application
127.0.0.1:54400 - - [21/Jan/2022:12:23:16] "WSREJECT /subscriptions" - -
2022-01-21 12:23:16,477 DEBUG    WebSocket closed for ['127.0.0.1', 54400]
127.0.0.1:54400 - - [21/Jan/2022:12:23:16] "WSDISCONNECT /subscriptions" - -

wscat

> root # wscat -c ws://localhost:8001/subscriptions
error: Unexpected server response: 403

Seems like authorization error. I've tried with
OriginValidator(URLRouter(websocket_urlpatterns), ["*"]), but no luck. I think it's related to graphql-ws configurations that I set up or maybe some steps I'm missing?

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant