diff --git a/aleksis/core/schema/__init__.py b/aleksis/core/schema/__init__.py index deab0e28b5d93e854a020aad687a618817196536..5004c0080bc14665c0e557f898dbf4ab4e1069a8 100644 --- a/aleksis/core/schema/__init__.py +++ b/aleksis/core/schema/__init__.py @@ -19,6 +19,7 @@ from .group import GroupType # noqa from .installed_apps import AppType from .message import MessageType from .notification import MarkNotificationReadMutation, NotificationType +from .oauth import OAuthQuery from .pdf import PDFFileType from .person import PersonMutation, PersonType from .school_term import SchoolTermType # noqa @@ -59,6 +60,8 @@ class Query(graphene.ObjectType): two_factor = graphene.Field(TwoFactorType) + oauth = graphene.Field(OAuthQuery) + def resolve_ping(root, info, payload) -> str: return payload @@ -157,6 +160,10 @@ class Query(graphene.ObjectType): return None return info.context.user + @staticmethod + def resolve_oauth(root, info, **kwargs): + return True + class Mutation(graphene.ObjectType): update_person = PersonMutation.Field() diff --git a/aleksis/core/schema/oauth.py b/aleksis/core/schema/oauth.py new file mode 100644 index 0000000000000000000000000000000000000000..74efa25615446097e758f57e16b6827bc275b2cf --- /dev/null +++ b/aleksis/core/schema/oauth.py @@ -0,0 +1,38 @@ +import graphene +from graphene_django import DjangoObjectType + +from aleksis.core.models import OAuthAccessToken, OAuthApplication + +from .base import FieldFileType + + +class OAuthScope(graphene.ObjectType): + name = graphene.String() + description = graphene.String() + + +class OAuthApplicationType(DjangoObjectType): + icon = graphene.Field(FieldFileType) + + class Meta: + model = OAuthApplication + fields = ["id", "name", "icon"] + + +class OAuthAccessTokenType(DjangoObjectType): + scopes = graphene.List(OAuthScope) + + @staticmethod + def resolve_scopes(root: OAuthAccessToken, info, **kwargs): + return [OAuthScope(name=key, description=value) for key, value in root.scopes.items()] + + class Meta: + model = OAuthAccessToken + fields = ["id", "application", "expires", "created", "updated"] + + +class OAuthQuery(graphene.ObjectType): + access_tokens = graphene.List(OAuthAccessTokenType) + + def resolve_access_tokens(root, info, **kwargs): + return OAuthAccessToken.objects.filter(user=info.context.user)