Skip to content

Commit 9c21c51

Browse files
committed
feat : accessToken 시간 늘리기
1 parent 58212e2 commit 9c21c51

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

app/user/auth.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# 환경 변수 설정
1515
SECRET_KEY = os.getenv("SECRET_KEY")
1616
ALGORITHM = "HS256"
17-
ACCESS_TOKEN_EXPIRE_MINUTES = int(os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES", 60)) # 1시간
17+
ACCESS_TOKEN_EXPIRE_DAYS = int(os.getenv("ACCESS_TOKEN_EXPIRE_DAYS", 14)) # 1시간
1818
REFRESH_TOKEN_EXPIRE_DAYS = int(os.getenv("REFRESH_TOKEN_EXPIRE_DAYS", 14)) # 2주
1919

2020
# OAuth2 설정
@@ -31,15 +31,17 @@ def verify_password(plain_password: str, hashed_password: str) -> bool:
3131
# 액세스 토큰 생성
3232
def create_access_token(data: dict):
3333
to_encode = data.copy()
34-
expire = datetime.utcnow() + timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES)
35-
to_encode.update({"exp": expire})
34+
expire = datetime.utcnow() + timedelta(minutes=ACCESS_TOKEN_EXPIRE_DAYS)
35+
to_encode.update({"exp": expire,
36+
"sub": data.get("sub")})
3637
return jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
3738

3839
# 리프레시 토큰 생성
3940
def create_refresh_token(data: dict):
4041
to_encode = data.copy()
4142
expire = datetime.utcnow() + timedelta(days=REFRESH_TOKEN_EXPIRE_DAYS)
42-
to_encode.update({"exp": expire})
43+
to_encode.update({"exp": expire,
44+
"sub": data.get("sub")})
4345
return jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
4446

4547
# JWT 토큰 검증 & 예외 처리 개선

0 commit comments

Comments
 (0)