diff options
author | Parker <contact@pkrm.dev> | 2024-11-04 21:14:18 -0600 |
---|---|---|
committer | Parker <contact@pkrm.dev> | 2024-11-04 21:14:18 -0600 |
commit | 5a0777033f6733c33fbd6119ade812e0c749be44 (patch) | |
tree | 22abb7d688f5551937ccc71c173e18b444e55eae /api/util | |
parent | d4280d1fda2f4809274793e7bd49f484f57a883e (diff) |
Work on refresh tokens
Diffstat (limited to 'api/util')
-rw-r--r-- | api/util/authentication.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/api/util/authentication.py b/api/util/authentication.py index 507b806..b8ac6a6 100644 --- a/api/util/authentication.py +++ b/api/util/authentication.py @@ -4,7 +4,7 @@ from fastapi import Depends, HTTPException, status from fastapi.security import OAuth2PasswordBearer from jwt.exceptions import InvalidTokenError from datetime import datetime, timedelta -from typing import Annotated +from typing import Annotated, Optional import jwt from api.util.db_dependency import get_db @@ -59,8 +59,23 @@ def create_access_token(data: dict, expires_delta: timedelta): return encoded_jwt -async def get_current_user( +# Backwards kinda of way to get refresh token support +# 'refresh_get_current_user' is only called from /refresh +# and alerts 'current_user' that it should expect a refresh token +async def get_current_user(token: Annotated[str, Depends(oauth2_scheme)]): + user = await current_user(token) + return user + + +async def refresh_get_current_user( token: Annotated[str, Depends(oauth2_scheme)], +): + user = await current_user(token, is_refresh=True) + return user + + +async def current_user( + token: str, is_refresh: bool = False, db=Depends(get_db), ): |