diff --git a/bsition/api/api.py b/bsition/api/api.py index c5a0401..30ea74f 100644 --- a/bsition/api/api.py +++ b/bsition/api/api.py @@ -1,13 +1,17 @@ from fastapi import APIRouter, Depends from fastapi.responses import JSONResponse -from bsition.api.endpoints import documents, token, tables, users +from bsition.api.endpoints import documents, tables, token, users from bsition.api.utils.security import get_current_user router = APIRouter() router.include_router(token.router) -router.include_router(documents.router, prefix="/documents", dependencies=[Depends(get_current_user)]) +router.include_router( + documents.router, prefix="/documents", dependencies=[Depends(get_current_user)] +) router.include_router(users.router, prefix="/users") -router.include_router(tables.router, prefix="/tables", dependencies=[Depends(get_current_user)]) +router.include_router( + tables.router, prefix="/tables", dependencies=[Depends(get_current_user)] +) diff --git a/bsition/api/endpoints/token.py b/bsition/api/endpoints/token.py index 6ac067c..d458eff 100644 --- a/bsition/api/endpoints/token.py +++ b/bsition/api/endpoints/token.py @@ -1,4 +1,4 @@ -from fastapi import APIRouter, HTTPException, Depends +from fastapi import APIRouter, Depends, HTTPException from fastapi.responses import JSONResponse from fastapi.security import OAuth2PasswordRequestForm @@ -21,6 +21,7 @@ def login(form: OAuth2PasswordRequestForm = Depends()): return JSONResponse( content={ "access_token": write_token({"sub": form.username}), - "token_type": "bearer"}, + "token_type": "bearer", + }, status_code=202, ) diff --git a/bsition/api/endpoints/users.py b/bsition/api/endpoints/users.py index 8242a53..24292ca 100644 --- a/bsition/api/endpoints/users.py +++ b/bsition/api/endpoints/users.py @@ -1,4 +1,4 @@ -from fastapi import APIRouter, HTTPException, Request, Depends +from fastapi import APIRouter, Depends, HTTPException, Request from fastapi.responses import JSONResponse from bsition.api.models.user import User diff --git a/bsition/api/utils/jwt.py b/bsition/api/utils/jwt.py index 2f237d6..0b01c45 100644 --- a/bsition/api/utils/jwt.py +++ b/bsition/api/utils/jwt.py @@ -10,6 +10,7 @@ def expire_date(days: int): # TODO: migrar a librería 'jose' + def write_token(data: dict): return encode( payload={**data, "exp": expire_date(1)}, key=getenv("SECRET"), algorithm="HS256"