From 57c3cca30df499d663b9bf5e41ca19d627b1291e Mon Sep 17 00:00:00 2001 From: Ian Eaves Date: Thu, 2 Nov 2023 22:24:45 -0500 Subject: [PATCH] Bearer handling --- grai-server/app/auth/validation.py | 2 -- grai-server/app/scripts/test.py | 9 --------- grai-server/app/workspaces/permissions.py | 14 ++++++++++++-- 3 files changed, 12 insertions(+), 13 deletions(-) delete mode 100644 grai-server/app/scripts/test.py diff --git a/grai-server/app/auth/validation.py b/grai-server/app/auth/validation.py index d708387ef..85660df51 100644 --- a/grai-server/app/auth/validation.py +++ b/grai-server/app/auth/validation.py @@ -14,8 +14,6 @@ def _generate_token(user: User) -> str: def send_validation_email(user: User): token = _generate_token(user) - print(token) - c = { "base_url": config("FRONTEND_URL", "http://localhost:3000"), "token": token, diff --git a/grai-server/app/scripts/test.py b/grai-server/app/scripts/test.py deleted file mode 100644 index 546228b5c..000000000 --- a/grai-server/app/scripts/test.py +++ /dev/null @@ -1,9 +0,0 @@ -import os - -import django - -os.environ["DJANGO_SETTINGS_MODULE"] = "the_guide.settings.dev" -django.setup() -import lineage.serializers as s - -print(repr(s.EdgeSerializer())) diff --git a/grai-server/app/workspaces/permissions.py b/grai-server/app/workspaces/permissions.py index baafca486..e794bc540 100755 --- a/grai-server/app/workspaces/permissions.py +++ b/grai-server/app/workspaces/permissions.py @@ -1,7 +1,17 @@ -from rest_framework_api_key.permissions import BaseHasAPIKey - +from rest_framework_api_key.permissions import BaseHasAPIKey, KeyParser, APIKey +from django.http import HttpRequest +import re from .models import WorkspaceAPIKey +class BearerKeyParser(KeyParser): + keyword = "Bearer" + + +class BearerApiKey(BaseHasAPIKey): + model = APIKey + key_parser = BearerKeyParser() + + class HasWorkspaceAPIKey(BaseHasAPIKey): model = WorkspaceAPIKey