selfprivacy-rest-api/selfprivacy_api/graphql/__init__.py
Inex Code 66a2bc8a0c test
2024-07-04 20:58:57 +04:00

30 lines
1.1 KiB
Python

"""GraphQL API for SelfPrivacy."""
# pylint: disable=too-few-public-methods
import typing
from strawberry.permission import BasePermission
from strawberry.types import Info
from selfprivacy_api.actions.api_tokens import is_token_valid
class IsAuthenticated(BasePermission):
"""Is authenticated permission"""
message = "You must be authenticated to access this resource."
def has_permission(self, source: typing.Any, info: Info, **kwargs) -> bool:
connection_params = info.context.get("connection_params")
print("Printing connection params from the ws connect!")
print(connection_params)
token = info.context["request"].headers.get("Authorization")
if token is None:
token = info.context["request"].query_params.get("token")
if token is None:
connection_params = info.context.get("connection_params")
print("Printing connection params from the ws connect!")
print(connection_params)
token = connection_params.get("Authorization")
if token in None:
return False
return is_token_valid(token.replace("Bearer ", ""))