mirror of
https://github.com/kurbezz/discord-bot.git
synced 2025-12-06 07:05:36 +01:00
Add token generation
This commit is contained in:
@@ -31,6 +31,8 @@ class Config(BaseModel):
|
||||
|
||||
WEB_APP_HOST: str
|
||||
|
||||
SECRET_KEY: str
|
||||
|
||||
|
||||
def get_config() -> Config:
|
||||
settings = Settings() # type: ignore
|
||||
|
||||
@@ -4,12 +4,15 @@ from core.mongo import mongo_manager
|
||||
from core.redis import redis_manager
|
||||
from core.broker import broker
|
||||
|
||||
from .auth.authx import auth
|
||||
from .views import routes
|
||||
|
||||
|
||||
def get_app() -> FastAPI:
|
||||
app = FastAPI()
|
||||
|
||||
auth.handle_errors(app)
|
||||
|
||||
for route in routes:
|
||||
app.include_router(route)
|
||||
|
||||
|
||||
12
src/modules/web_app/auth/authx.py
Normal file
12
src/modules/web_app/auth/authx.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from authx import AuthX, AuthXConfig
|
||||
|
||||
from core.config import config
|
||||
|
||||
|
||||
config = AuthXConfig(
|
||||
JWT_ALGORITHM = "HS256",
|
||||
JWT_SECRET_KEY = config.SECRET_KEY,
|
||||
JWT_TOKEN_LOCATION = ["headers"],
|
||||
)
|
||||
|
||||
auth = AuthX(config=config)
|
||||
@@ -5,6 +5,7 @@ from domain.users import CreateUser
|
||||
from modules.web_app.services.oauth.process_callback import process_callback
|
||||
from modules.web_app.services.oauth.authorization_url_getter import get_authorization_url as gen_auth_link
|
||||
from modules.web_app.serializers.auth import GetAuthorizationUrlResponse
|
||||
from modules.web_app.auth.authx import auth
|
||||
from repositories.users import UserRepository
|
||||
|
||||
|
||||
@@ -29,4 +30,6 @@ async def callback(provider: OAuthProvider, code: str):
|
||||
)
|
||||
)
|
||||
|
||||
return {"user": user.model_dump()}
|
||||
token = auth.create_access_token(uid=user.id, data={"is_admin": user.is_admin})
|
||||
|
||||
return {"token": token}
|
||||
|
||||
Reference in New Issue
Block a user