From c6eaf497796f8fce0fce969770c2b064d23074f4 Mon Sep 17 00:00:00 2001 From: sam Date: Mon, 1 Apr 2024 21:36:24 +0200 Subject: [PATCH] add discord auth skeleton --- foxnouns/app.py | 2 +- foxnouns/blueprints/v2/auth/__init__.py | 43 +++++++++++++++++++++++++ foxnouns/blueprints/v2/auth/discord.py | 15 +++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 foxnouns/blueprints/v2/auth/__init__.py create mode 100644 foxnouns/blueprints/v2/auth/discord.py diff --git a/foxnouns/app.py b/foxnouns/app.py index af561a8..ef3fb2e 100644 --- a/foxnouns/app.py +++ b/foxnouns/app.py @@ -6,7 +6,7 @@ from . import blueprints from .db.aio import async_session from .db.util import validate_token from .exceptions import ErrorCode, ExpectedError -from .settings import SECRET_KEY, BASE_DOMAIN +from .settings import BASE_DOMAIN, SECRET_KEY app = Quart(__name__, host_matching=True, static_host=BASE_DOMAIN) app.secret_key = SECRET_KEY diff --git a/foxnouns/blueprints/v2/auth/__init__.py b/foxnouns/blueprints/v2/auth/__init__.py new file mode 100644 index 0000000..8d5c920 --- /dev/null +++ b/foxnouns/blueprints/v2/auth/__init__.py @@ -0,0 +1,43 @@ +from datetime import datetime + +from pydantic import BaseModel, Field + +from foxnouns.models.user import SelfUserModel + + +class OAuthCallbackRequest(BaseModel): + callback_domain: str + code: str + state: str + + +class BaseCallbackResponse(BaseModel): + """The base class for callback responses.""" + + has_account: bool + + +class ExistingUserCallbackResponse(BaseCallbackResponse): + """The class returned when a user already exists.""" + + token: str + user: SelfUserModel + + +class NewUserCallbackResponse(BaseCallbackResponse): + """The class returned when the user is new and has to create an account.""" + + remote_username: str + ticket: str + require_captcha: bool + + +class DeletedUserCallbackResponse(BaseCallbackResponse): + """The class returned when the user has been deleted.""" + + token: str + user: SelfUserModel + + deleted_at: datetime + self_delete: bool + delete_reason: str | None = Field(default=None) diff --git a/foxnouns/blueprints/v2/auth/discord.py b/foxnouns/blueprints/v2/auth/discord.py new file mode 100644 index 0000000..ff2774f --- /dev/null +++ b/foxnouns/blueprints/v2/auth/discord.py @@ -0,0 +1,15 @@ +from quart import Blueprint +from quart_schema import validate_request, validate_response + +from foxnouns.settings import BASE_DOMAIN + +from . import BaseCallbackResponse, OAuthCallbackRequest + +bp = Blueprint("discord", __name__) + + +@bp.post("/api/v2/auth/discord/callback", host=BASE_DOMAIN) +@validate_request(OAuthCallbackRequest) +@validate_response(BaseCallbackResponse) +async def discord_callback(data: OAuthCallbackRequest): + raise NotImplementedError()