diff options
author | Parker <contact@pkrm.dev> | 2024-11-04 23:01:13 -0600 |
---|---|---|
committer | Parker <contact@pkrm.dev> | 2024-11-04 23:01:13 -0600 |
commit | 3f8e39cc86ca22c3e94f52d693c90553ef1dfd57 (patch) | |
tree | 0bf2ef55e3250d059f1bdaf8546f2c1f2773ad52 /app/routes/refresh_route.py | |
parent | 5a0777033f6733c33fbd6119ade812e0c749be44 (diff) |
Major consolidation and upgrades
Diffstat (limited to 'app/routes/refresh_route.py')
-rw-r--r-- | app/routes/refresh_route.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/app/routes/refresh_route.py b/app/routes/refresh_route.py new file mode 100644 index 0000000..6bc8797 --- /dev/null +++ b/app/routes/refresh_route.py @@ -0,0 +1,33 @@ +from fastapi import Depends, APIRouter +from fastapi.responses import RedirectResponse +from datetime import timedelta +from typing import Annotated + +from app.util.authentication import ( + create_access_token, + refresh_get_current_user, +) +from app.schemas.auth_schemas import Token, User + + +router = APIRouter(prefix="/refresh", tags=["refresh"]) + + +# Full native JWT support is not complete in FastAPI yet :( +# Part of that is token refresh, so we must implement it ourselves +@router.post("/") +async def refresh_access_token( + current_user: Annotated[User, Depends(refresh_get_current_user)], +) -> Token: + """ + Return a new access token if the refresh token is valid + """ + access_token_expires = timedelta(minutes=30) + access_token = create_access_token( + data={"sub": current_user.username, "refresh": False}, + expires_delta=access_token_expires, + ) + return Token( + access_token=access_token, + token_type="bearer", + ) |