Skip to content
Snippets Groups Projects
Commit 51c0757d authored by jan.bednarik's avatar jan.bednarik
Browse files

Remove Flask.

parent 1db669e7
No related branches found
No related tags found
No related merge requests found
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()
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'])
......
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:
......
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}))
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment