From 449908458c02d86d912bc84c26c0f80b844c8c79 Mon Sep 17 00:00:00 2001 From: "Shahin M. Shahin" Date: Sat, 17 Aug 2024 14:36:11 +0300 Subject: [PATCH] Introduce GitHub OAuth Authentication This implements the long waited GitHub Auth allows 3 options: 1- Registering with GitHub 2- Linking your existing profile with GitHub 3- Logging in with GitHub Two variables are needed `GITHUB_CLIENT_ID`, `GITHUB_CLIENT_SECRET` instructions are written as comments in the code. --- server/fishtest/__init__.py | 4 + server/fishtest/schemas.py | 31 +++-- server/fishtest/templates/login.mak | 10 ++ server/fishtest/templates/signup.mak | 9 ++ server/fishtest/templates/user.mak | 20 ++- server/fishtest/userdb.py | 53 ++++++-- server/fishtest/views.py | 194 ++++++++++++++++++++++++++- 7 files changed, 294 insertions(+), 27 deletions(-) diff --git a/server/fishtest/__init__.py b/server/fishtest/__init__.py index 3fcf99ec6..7adae958f 100644 --- a/server/fishtest/__init__.py +++ b/server/fishtest/__init__.py @@ -177,5 +177,9 @@ def group_finder(username, request): config.add_route("api_actions", "/api/actions") config.add_route("api_calc_elo", "/api/calc_elo") + # GitHub OAuth Routes + config.add_route("github_oauth", "/github/oauth") + config.add_route("github_callback", "/github/callback") + config.scan() return config.make_wsgi_app() diff --git a/server/fishtest/schemas.py b/server/fishtest/schemas.py index 45ed5db4c..9a7c5ab3b 100644 --- a/server/fishtest/schemas.py +++ b/server/fishtest/schemas.py @@ -87,18 +87,25 @@ def size_is_length(x): size_is_length, ) -user_schema = { - "_id?": ObjectId, - "username": username, - "password": str, - "registration_time": datetime_utc, - "pending": bool, - "blocked": bool, - "email": email, - "groups": [str, ...], - "tests_repo": union("", url), - "machine_limit": uint, -} +user_schema = intersect( + { + "_id?": ObjectId, + "username": username, + "password?": str, + "registration_time": datetime_utc, + "pending": bool, + "blocked": bool, + "email?": email, + "github_id?": str, + "linked_github_username?": str, + "github_access_token?": str, + "groups": [str, ...], + "tests_repo?": union("", url), + "machine_limit": uint, + }, + at_least_one_of("email", "github_id"), + at_least_one_of("password", "github_access_token"), +) worker_schema = { diff --git a/server/fishtest/templates/login.mak b/server/fishtest/templates/login.mak index 7160b2922..1bcfcef1c 100644 --- a/server/fishtest/templates/login.mak +++ b/server/fishtest/templates/login.mak @@ -58,6 +58,16 @@ + +
+

Or

+
+ + +
+