diff --git a/openlobby/core/auth.py b/openlobby/core/auth.py index 6596f41e3d19be9fd5e8375f04beac21d6ef4b1a..5081865a81146c0f16b7c4a19bd4b80f1543aac6 100644 --- a/openlobby/core/auth.py +++ b/openlobby/core/auth.py @@ -1,10 +1,7 @@ from django.conf import settings import json import jwt -import re import time -from flask import g, request -from flask_graphql import GraphQLView def get_login_attempt_expiration_time(): @@ -32,30 +29,3 @@ def parse_access_token(token): def graphql_error_response(message, code=400): error = {'message': message} return json.dumps({'errors': [error]}), code, {'Content-Type': 'application/json'} - - -class AuthGraphQLView(GraphQLView): - """ - GraphQLView which sets session_id into 'g' if authorization token is - provided in Authorization header. - """ - - def dispatch_request(self): - session_id = None - auth_header = request.headers.get('Authorization') - if auth_header is not None: - m = re.match(r'Bearer (?P<token>.+)', auth_header) - if m: - token = m.group('token') - else: - return graphql_error_response('Wrong Authorization header. Expected: "Bearer <token>"') - - try: - session_id = parse_access_token(token) - except jwt.InvalidTokenError: - session_id = None - except Exception: - return graphql_error_response('Wrong Authorization token.', 401) - - g.session_id = session_id - return super(AuthGraphQLView, self).dispatch_request() diff --git a/openlobby/core/mutations.py b/openlobby/core/mutations.py index a6b6086901506650a21b455437f303a01ceea5f5..63ca820a38de94682445925e1ee4f949dae46744 100644 --- a/openlobby/core/mutations.py +++ b/openlobby/core/mutations.py @@ -1,5 +1,4 @@ import arrow -from flask import g import graphene from graphene import relay from graphene.types.datetime import DateTime @@ -201,6 +200,8 @@ class Logout(relay.ClientIDMutation): if viewer is None: raise Exception('User must be logged in to perform this mutation.') + # TODO + raise NotImplementedError() session_id = g.get('session_id') session = SessionDoc.get(session_id, using=info.context['es'], index=info.context['index']) session.delete(using=info.context['es'], index=info.context['index']) diff --git a/openlobby/core/utils.py b/openlobby/core/utils.py index e26871b964847a96b0fc2ad20d335613fc47c256..e4dc0fdf805d59bd8f16b3bbed9f9fb4f9fdbe15 100644 --- a/openlobby/core/utils.py +++ b/openlobby/core/utils.py @@ -1,11 +1,12 @@ -from flask import g - from .documents import SessionDoc from .types import User def get_viewer(info): """Resolves actual viewer and caches it into 'g'.""" + # TODO + raise NotImplementedError + if not hasattr(g, 'viewer'): session_id = g.get('session_id', None) if session_id is None: diff --git a/openlobby/server.py b/openlobby/server.py deleted file mode 100644 index e35d9475071b2c223b820dbd1991a46a43f02c0a..0000000000000000000000000000000000000000 --- a/openlobby/server.py +++ /dev/null @@ -1,26 +0,0 @@ -import os -from flask import Flask -from elasticsearch import Elasticsearch - -from .auth import AuthGraphQLView -from .management import bootstrap_es -from .schema import schema -from .settings import ES_INDEX - - -app = Flask(__name__) - - -es_dsn = os.environ.get('ELASTICSEARCH_DSN', 'http://localhost:9200') -es_client = Elasticsearch(es_dsn) - -bootstrap_es(es_client, ES_INDEX) - - -@app.route('/') -def hello(): - return 'Open Lobby Server\n\nAPI is at: /graphql', 200, {'Content-Type': 'text/plain; charset=utf-8'} - - -app.add_url_rule('/graphql', view_func=AuthGraphQLView.as_view( - 'graphql', schema=schema, graphiql=True, context={'es': es_client, 'index': ES_INDEX})) diff --git a/requirements.txt b/requirements.txt index 47d9118200e231ece5b885c06d8e2da054579d4d..e3636923ccf3dbbd2900b67da9f4dab8bcdad146 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,6 @@ Django>=2,<2.1 graphene>=2.0,<3.0 graphene-django>=2.0,<3.0 -flask>=0.12,<0.13 -flask_graphQL>=1.4,<1.5 elasticsearch-dsl>=5.3.0,<6.0.0 pytest>=3.2.3,<3.3.0 pytest-django>=3.1.2,<3.2