From b89bb484b7da7a5aa94d2459b9234e440803f415 Mon Sep 17 00:00:00 2001 From: Gentile G Date: Thu, 3 Apr 2025 19:24:10 +0200 Subject: [PATCH] Adding all fastapi_users routes incluing Google and Discord --- api/.gitignore | 1 + api/rpk-api/__pycache__/main.cpython-313.pyc | Bin 784 -> 0 bytes .../hub/__pycache__/__init__.cpython-313.pyc | Bin 625 -> 0 bytes api/rpk-api/hub/auth/__init__.py | 17 +++++++++++++---- .../auth/__pycache__/__init__.cpython-313.pyc | Bin 2538 -> 0 bytes .../user/__pycache__/__init__.cpython-313.pyc | Bin 1444 -> 0 bytes api/rpk-api/main.py | 15 +++++++++------ docker-compose.yml | 4 ++-- 8 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 api/.gitignore delete mode 100644 api/rpk-api/__pycache__/main.cpython-313.pyc delete mode 100644 api/rpk-api/hub/__pycache__/__init__.cpython-313.pyc delete mode 100644 api/rpk-api/hub/auth/__pycache__/__init__.cpython-313.pyc delete mode 100644 api/rpk-api/hub/user/__pycache__/__init__.cpython-313.pyc diff --git a/api/.gitignore b/api/.gitignore new file mode 100644 index 0000000..e7078d0 --- /dev/null +++ b/api/.gitignore @@ -0,0 +1 @@ +*/__pycache__/* diff --git a/api/rpk-api/__pycache__/main.cpython-313.pyc b/api/rpk-api/__pycache__/main.cpython-313.pyc deleted file mode 100644 index 3efdc308c4c4d9d8486fbc945be564bb63ad9993..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 784 zcmZ8e&ubGw82x5vHj`|A7~A@z?ZK$02sR3q(juY=q74-3c<5nanI@afYO=e`?v^&E z(u+NMDfH-3!GlNtjq1TNA{3;D9)xJ{;LVveMd>U%^S;VIYny`!ns%dOAjb$uwhH;ZDo5HMtonvHa4S-()%`ux)P@Aq+PbL4Y z*MQ|1WqDR$)*?}zh!t&o$6%!ycuwZWL{YG@VwUX!t1KGAvaMC6e0JC-JIAUG#Lh1& zKb~2iIMI|kl9N2%3R{jV>y19co#E z3uFWKR8Af&;0~&zmAA^J&`%KS-kO|hD4m9gUfkr7-_RE3qAi*4`5iZocpxf@Rnm0b za{}A&D-WjiJ0_~!p#?OcO2BVy+^!q4Ai^+lBA#@!wn3?(uiEg!(CfL9=t8k_k#IZy zrX&gX;(AG10h7O zy=27?TD`RGjw2S@{Yd>F%9+63e%MZX?maQ9N*zKh)HK8hp|5b`7-o;*>JcvP4nE=O zFJ$776kj%Xny;+a)9fgc6kOY}W4lQjg#)zBfoqV63zv!tAvpvD4iGh_7Zk}_e~_%OcdhmM5Ke^? ze*n&0`8heYT2z7569=S7`2*}ajVku=-ptd}%sgq=&87{+>wNn=n<@ZYNwR(VHCTTZ z;4AQfuZ#fQbcL#dt0T>;(b`=((?+^yP{XU!x@S_en$<>@XH#2Xo$gH4$(^nAO`jax z;4PZ&_=aD9q|(;3<(o1F-JK~t>yKP`(^I%PBvF|qnDsQ?9>5|QyCs{uQAA42cx#YA zj1oCNEfUH*8!qt>G8l@v(9oZwB#l4rWdzSi93DGPN+OufNx_aE9vwb7;%31hjv+JV|nz6v7rVL@;m0*J=TVS<-8Bl@$C|Mi`;}ss^xF;0O_}SCkuJ6^v@)4BmbZ zg?^5LQsgT7aY$?O(CS)4E|~cuhM1v<)+KEW-M8+*^`8Z&lUKa?zd^^9PA|u=rTNno ziHzKcHeHRwA7Cvc0Pi|5&mEe7xG#*Ic^NuEfG}b~(9aj#e4LTEOp_;cPb`by0E!o) ztTaVYegf+X>|cU|U*Kd3PA{LhK(T7q0sN diff --git a/api/rpk-api/hub/auth/__init__.py b/api/rpk-api/hub/auth/__init__.py index eeaafcd..6376dd5 100644 --- a/api/rpk-api/hub/auth/__init__.py +++ b/api/rpk-api/hub/auth/__init__.py @@ -1,20 +1,21 @@ import os import uuid +from beanie import PydanticObjectId from fastapi import Depends -from fastapi_users import UUIDIDMixin, BaseUserManager +from fastapi_users import UUIDIDMixin, BaseUserManager, FastAPIUsers, schemas from fastapi_users.authentication import AuthenticationBackend, BearerTransport from fastapi_users.authentication.strategy import AccessTokenDatabase, DatabaseStrategy from fastapi_users_db_beanie.access_token import BeanieBaseAccessTokenDocument, BeanieAccessTokenDatabase from httpx_oauth.clients.google import GoogleOAuth2 -from fastapi_users.fastapi_users import get_oauth_router +from httpx_oauth.clients.discord import DiscordOAuth2 from hub.user import User, get_user_db SECRET = os.getenv("FASTAPI_USERS_SECRET") google_oauth_client = GoogleOAuth2(os.getenv("GOOGLE_CLIENT_ID"), os.getenv("GOOGLE_CLIENT_SECRET")) - +discord_oauth_client = DiscordOAuth2(os.getenv("DISCORD_CLIENT_ID"), os.getenv("DISCORD_CLIENT_SECRET")) TOKEN_LIFETIME = 3600 @@ -49,4 +50,12 @@ auth_backend = AuthenticationBackend( get_strategy=get_database_strategy, ) -oauth_router = get_oauth_router(google_oauth_client, auth_backend, get_user_manager, SECRET) +fastapi_users = FastAPIUsers[User, PydanticObjectId](get_user_manager, [auth_backend]) + +auth_router = fastapi_users.get_auth_router(auth_backend, requires_verification=True) +register_router = fastapi_users.get_register_router(schemas.BaseUser, schemas.BaseUserCreate) +password_router = fastapi_users.get_reset_password_router() +verification_router = fastapi_users.get_verify_router(schemas.BaseUser) +users_router = fastapi_users.get_users_router(schemas.BaseUser, schemas.BaseUserUpdate) +google_oauth_router = fastapi_users.get_oauth_router(google_oauth_client, auth_backend, SECRET) +discord_oauth_router = fastapi_users.get_oauth_router(discord_oauth_client, auth_backend, SECRET) diff --git a/api/rpk-api/hub/auth/__pycache__/__init__.cpython-313.pyc b/api/rpk-api/hub/auth/__pycache__/__init__.cpython-313.pyc deleted file mode 100644 index 71a18361ea14ead0fc1040ce3689b8779d263030..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2538 zcmaJ?OKcNY6n$fl|Bmg%u}R{5947<}#i2k7Q7a%2gJS1XWo%W5kw#;CVg?f1y)&lJ z4QUr$bW=8{EUT(g!;Y@H>7weUT{<$0^ih<4R8=f0ktVIwUGJM22RjlSY2Lj1dH3DV zxp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