diff --git a/app/controllers/Auth.py b/app/controllers/Auth.py index 1a28540..960932d 100644 --- a/app/controllers/Auth.py +++ b/app/controllers/Auth.py @@ -1,7 +1,10 @@ import os +import toml from pydantic import BaseModel +config: dict = toml.load("config.toml") + class PasetoSettings(BaseModel): authpaseto_secret_key: str = os.environ['SECRET_KEY'] - authpaseto_access_token_expires: int = 86400 + authpaseto_access_token_expires: int | bool = config['auth']['access_token_expires'] \ No newline at end of file diff --git a/app/models/ResponseModels.py b/app/models/ResponseModels.py index ee4cfd7..083ac8d 100644 --- a/app/models/ResponseModels.py +++ b/app/models/ResponseModels.py @@ -68,7 +68,6 @@ class ClientAuthTokenResponse(BaseModel): """ access_token: str - refresh_token: str class ClientTokenRefreshResponse(BaseModel): """Implements the response fields for client token refresh. diff --git a/app/routers/auth.py b/app/routers/auth.py index cbbbecd..e1f77d5 100644 --- a/app/routers/auth.py +++ b/app/routers/auth.py @@ -6,20 +6,16 @@ import app.models.ClientModels as ClientModels import app.models.GeneralErrors as GeneralErrors import app.models.ResponseModels as ResponseModels -router = APIRouter( - prefix="/auth", - tags=['Authentication'] -) +router = APIRouter() clients = Clients() config: dict = load_config() -@router.post('/', response_model=ResponseModels.ClientAuthTokenResponse, status_code=status.HTTP_200_OK) +@router.post('/auth', response_model=ResponseModels.ClientAuthTokenResponse, status_code=status.HTTP_200_OK, tags=['Authentication']) async def auth(request: Request, response: Response, client: ClientModels.ClientAuthModel, Authorize: AuthPASETO = Depends()) -> dict: """Authenticate a client and get an auth token. Returns: access_token: auth token - refresh_token: refresh token """ admin_claim: dict[str, bool] @@ -43,36 +39,10 @@ async def auth(request: Request, response: Response, client: ClientModels.Client user_claims=admin_claim, fresh=True) - refresh_token = Authorize.create_refresh_token(subject=client.id, - user_claims=admin_claim) - - return {"access_token": access_token, "refresh_token": refresh_token} + return {"access_token": access_token} else: raise HTTPException(status_code=401, detail={ "error": GeneralErrors.Unauthorized().error, "message": GeneralErrors.Unauthorized().message } - ) - -@router.post('/refresh', response_model=ResponseModels.ClientTokenRefreshResponse, - status_code=status.HTTP_200_OK, tags=['Authentication']) -async def refresh(request: Request, response: Response, - Authorize: AuthPASETO = Depends()) -> dict: - """Refresh an auth token. - - Returns: - access_token: auth token - """ - - Authorize.paseto_required(refresh_token=True) - - admin_claim: dict[str, bool] = {"admin": False} - - current_user: str | int | None = Authorize.get_subject() - - if 'admin' in Authorize.get_token_payload(): - admin_claim = {"admin": Authorize.get_token_payload()['admin']} - - return {"access_token": Authorize.create_access_token(subject=current_user, - user_claims=admin_claim, - fresh=False)} \ No newline at end of file + ) \ No newline at end of file diff --git a/config.toml b/config.toml index 949a91d..b45c3e8 100644 --- a/config.toml +++ b/config.toml @@ -54,6 +54,9 @@ database = 4 [mirrors] database = 5 +[auth] +access_token_expires = false + [app] repositories = ["TeamVanced/VancedMicroG", "revanced/revanced-cli", "revanced/revanced-patcher", "revanced/revanced-patches", "revanced/revanced-integrations", "revanced/revanced-manager", "revanced/revanced-website"]