mirror of
https://github.com/maxdorninger/MediaManager.git
synced 2026-04-27 11:15:32 +02:00
moving AuthConfig Class
This commit is contained in:
@@ -7,7 +7,7 @@ from fastapi.security import OAuth2PasswordBearer
|
||||
from jwt.exceptions import InvalidTokenError
|
||||
from pydantic import BaseModel
|
||||
|
||||
from config import AuthConfig
|
||||
from auth.config import AuthConfig
|
||||
from database import SessionDependency
|
||||
from database.users import User
|
||||
|
||||
@@ -34,11 +34,11 @@ async def get_current_user(db: SessionDependency, token: str = Depends(oauth2_sc
|
||||
detail="Could not validate credentials",
|
||||
headers={"WWW-Authenticate": "Bearer"},
|
||||
)
|
||||
config = AuthConfig()
|
||||
auth_config = AuthConfig
|
||||
log.debug("token: " + token)
|
||||
|
||||
try:
|
||||
payload = jwt.decode(token, config.jwt_signing_key, algorithms=[config.jwt_signing_algorithm])
|
||||
payload = jwt.decode(token, auth_config.jwt_signing_key, algorithms=[auth_config.jwt_signing_algorithm])
|
||||
log.debug("jwt payload: " + payload.__str__())
|
||||
user_uid: str = payload.get("sub")
|
||||
log.debug("jwt payload sub (USER uid): " + user_uid)
|
||||
|
||||
13
backend/src/auth/config.py
Normal file
13
backend/src/auth/config.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
|
||||
class AuthConfig(BaseSettings):
|
||||
# to get a signing key run:
|
||||
# openssl rand -hex 32
|
||||
jwt_signing_key: str
|
||||
jwt_signing_algorithm: str = "HS256"
|
||||
jwt_access_token_lifetime: int = 60 * 24 * 30
|
||||
|
||||
@property
|
||||
def jwt_signing_key(self):
|
||||
return self._jwt_signing_key
|
||||
@@ -13,16 +13,7 @@ class ProwlarrConfig(BaseModel):
|
||||
url: str = os.getenv("PROWLARR_URL")
|
||||
|
||||
|
||||
class AuthConfig(BaseModel):
|
||||
# to get a signing key run:
|
||||
# openssl rand -hex 32
|
||||
_jwt_signing_key: str = os.getenv("JWT_SIGNING_KEY")
|
||||
jwt_signing_algorithm: str = "HS256"
|
||||
jwt_access_token_lifetime: int = int(os.getenv("JWT_ACCESS_TOKEN_LIFETIME") or 60 * 24 * 30)
|
||||
|
||||
@property
|
||||
def jwt_signing_key(self):
|
||||
return self._jwt_signing_key
|
||||
|
||||
|
||||
class QbittorrentConfig(BaseModel):
|
||||
@@ -37,8 +28,4 @@ class DownloadClientConfig(BaseModel):
|
||||
|
||||
|
||||
class MachineLearningConfig(BaseModel):
|
||||
model_name: str = os.getenv("OLLAMA_MODEL_NAME") or "qwen2.5:0.5b"
|
||||
|
||||
|
||||
def get_db_config() -> DbConfig:
|
||||
return DbConfig()
|
||||
model_name: str = os.getenv("OLLAMA_MODEL_NAME") or "qwen2.5:0.5b"
|
||||
Reference in New Issue
Block a user