Compare commits

...

4 Commits

4 changed files with 24 additions and 7 deletions
+10
View File
@@ -0,0 +1,10 @@
config:
path_mode: relative
prompts:
preset: "下面的代码来自项目相对路径 {{path}}\n---\n{{content}}"
preset:
auth:
- "app/auth.py"
- "app/auth/*"
+4
View File
@@ -13,3 +13,7 @@ wheels/
*.json
*.log
.DS_Store
.git
+3 -3
View File
@@ -6,7 +6,7 @@ import secrets
from app.auth.deps import get_current_user
from app.db import SessionLocal
from app.models import User
from app.auth.jwt import create_access_token, create_refresh_token, decode_token
from app.auth.jwt import create_jwt_token, create_refresh_token, decode_token
router = APIRouter()
@@ -87,7 +87,7 @@ async def auth_callback(request: Request, code: str, state: str):
db.close()
jwt_token = create_access_token({
jwt_token = create_jwt_token({
"sub": user.id,
"email": user.email,
})
@@ -125,7 +125,7 @@ def refresh_token(refresh_token: str):
user_id = payload.get("sub")
new_access = create_access_token({"sub": user_id})
new_access = create_jwt_token({"sub": user_id})
return {"access_token": new_access}
+6 -3
View File
@@ -6,14 +6,17 @@ from fastapi import HTTPException, status
JWT_SECRET = os.getenv("JWT_SECRET")
JWT_ALGORITHM = os.getenv("JWT_ALGORITHM", "HS256")
ACCESS_TOKEN_EXPIRE_MINUTES = int(os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES", "60"))
REFRESH_TOKEN_EXPIRE_DAYS = int(os.getenv("REFRESH_TOKEN_EXPIRE_DAYS", "7"))
def now():
return datetime.now(timezone.utc)
def create_access_token(data: dict):
def create_jwt_token(data: dict):
payload = {
**data,
"type": "access",
"exp": now() + timedelta(minutes=60),
"exp": now() + timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES),
"iat": now(),
}
return jwt.encode(payload, JWT_SECRET, algorithm=JWT_ALGORITHM)
@@ -22,7 +25,7 @@ def create_refresh_token(data: dict):
payload = {
**data,
"type": "refresh",
"exp": now() + timedelta(days=7),
"exp": now() + timedelta(days=REFRESH_TOKEN_EXPIRE_DAYS),
"iat": now(),
}
return jwt.encode(payload, JWT_SECRET, algorithm=JWT_ALGORITHM)