Skip to content

Commit

Permalink
Merge pull request #174 from OZ-Coding-School/feat/token_name
Browse files Browse the repository at this point in the history
Feat/token name
  • Loading branch information
yoonju977 authored Sep 20, 2024
2 parents 2270dbd + 874dbdd commit f2e18ea
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 59 deletions.
18 changes: 0 additions & 18 deletions Dockerfile.jenkins

This file was deleted.

2 changes: 1 addition & 1 deletion ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ PR과 관련된 템플릿은 PR을 생성할때 자동으로 생성됩니다. <b
![image](https://github.com/user-attachments/assets/30229c1f-7f2c-47ba-a4d9-5875be6b1906)

### 사용자 액션 알림 처리(댓글, 채택, 좋아요, 신고, 훈수봇 답변)
(![알림처리 로직](https://github.com/user-attachments/assets/705f7807-0267-4b30-bdcc-0887584101ba)
![알림처리 로직](https://github.com/user-attachments/assets/705f7807-0267-4b30-bdcc-0887584101ba)


### AI 프롬프트 엔지니어링
Expand Down
2 changes: 1 addition & 1 deletion api/common/authentication/cookie_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def authenticate(self, request: Request) -> Optional[Tuple[AuthUser, Token]]:
header = self.get_header(request)
if header is None:
# Authorization 헤더가 없는 경우 쿠키에서 Access token을 읽는다.
raw_token = request.COOKIES.get("access")
raw_token = request.COOKIES.get("hunsu_access")
else:
raw_token = self.get_raw_token(header)

Expand Down
21 changes: 9 additions & 12 deletions api/users/utils.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import os
from dataclasses import dataclass, field
#from pathlib import Path

import pytz
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils import timezone
#from dotenv import load_dotenv
from rest_framework.permissions import BasePermission
from rest_framework_simplejwt.tokens import RefreshToken

#BASE_DIR = Path(__file__).resolve().parent.parent


@dataclass
class GoogleEnvironments:
Expand Down Expand Up @@ -80,12 +76,12 @@ def set_jwt_auth_cookie(self, response, jwt_tokens):
"""
response = self.set_cookie_attributes(
response=response,
key="access",
key="hunsu_access",
token=jwt_tokens["access"],
)
response = self.set_cookie_attributes(
response=response,
key="refresh",
key="hunsu_refresh",
token=jwt_tokens["refresh"],
)

Expand All @@ -98,9 +94,9 @@ def set_cookie_attributes(response, key, token):
key: access or refresh
token: jwt token
"""
if key == "access":
if key == "hunsu_access":
expires_at = HunsooKingAuthClass()._access_expiration
elif key == "refresh":
elif key == "hunsu_refresh":
expires_at = HunsooKingAuthClass()._refresh_expiration
else:
raise ValueError("key should be 'access' or 'refresh'")
Expand Down Expand Up @@ -183,21 +179,21 @@ def __init__(self):
def set_jwt_auth_cookie(self, response, jwt_tokens):
response = self.set_cookie_attributes(
response=response,
key="access",
key="hunsu_access",
token=jwt_tokens["access"],
)
response = self.set_cookie_attributes(
response=response,
key="refresh",
key="hunsu_refresh",
token=jwt_tokens["refresh"],
)
return response

@staticmethod
def set_cookie_attributes(response, key, token):
if key == "access":
if key == "hunsu_access":
expires_at = GeneralAuthClass()._access_expiration
elif key == "refresh":
elif key == "hunsu_refresh":
expires_at = GeneralAuthClass()._refresh_expiration
else:
raise ValueError("key should be 'access' or 'refresh'")
Expand All @@ -211,6 +207,7 @@ def set_cookie_attributes(response, key, token):
expires=expires_at,
path="/",
)

return response

@staticmethod
Expand Down
18 changes: 9 additions & 9 deletions api/users/views/user_auth_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class UserTokenVerifyView(generics.GenericAPIView):

def post(self, request, *args, **kwargs):
logger.info("POST /api/auth/token/verify")
token = request.COOKIES.get("access")
token = request.COOKIES.get("hunsu_access")
if not token:
logger.error("/api/auth/token/verify: Access token not found in cookies")
return Response(status=status.HTTP_400_BAD_REQUEST)
Expand All @@ -230,7 +230,7 @@ class UserTokenRefreshView(generics.GenericAPIView):

def post(self, request, *args, **kwargs):
logger.info("POST /api/auth/token/refresh")
refresh_token = request.COOKIES.get("refresh")
refresh_token = request.COOKIES.get("hunsu_refresh")

if not refresh_token:
logger.error("/api/auth/token/refresh: Refresh token not found in cookies")
Expand Down Expand Up @@ -258,7 +258,7 @@ def post(self, request, *args, **kwargs):
)
try:
HunsooKingAuthClass.set_cookie_attributes(
response=response, key="access", token=access_token
response=response, key="hunsu_access", token=access_token
)
except ValueError:
logger.error("/api/auth/token/refresh: Failed to set access token cookie")
Expand All @@ -277,7 +277,7 @@ class UserLogoutView(generics.GenericAPIView):

def post(self, request, *args, **kwargs):
serializer = self.get_serializer(
data={"refresh_token": request.COOKIES.get("refresh")}
data={"refresh_token": request.COOKIES.get("hunsu_refresh")}
)
serializer.is_valid(raise_exception=True)

Expand All @@ -287,10 +287,10 @@ def post(self, request, *args, **kwargs):
refresh_token.blacklist()
response = Response(status=status.HTTP_200_OK)
response.delete_cookie(
"access", domain=os.getenv("COOKIE_DOMAIN"), path="/"
"hunsu_access", domain=os.getenv("COOKIE_DOMAIN"), path="/"
)
response.delete_cookie(
"refresh", domain=os.getenv("COOKIE_DOMAIN"), path="/"
"hunsu_refresh", domain=os.getenv("COOKIE_DOMAIN"), path="/"
)
logger.info("/api/auth/logout: Logout successful")
return response
Expand All @@ -315,7 +315,7 @@ def delete(self, request, *args, **kwargs):
logger.info(f"DELETE /api/auth/delete for user: {request.user.email}")

# refresh_token을 쿠키에서 가져옴
refresh_token = request.COOKIES.get("refresh")
refresh_token = request.COOKIES.get("hunsu_refresh")
if not refresh_token:
logger.error("Refresh token not found in cookies")
return Response(
Expand All @@ -334,10 +334,10 @@ def delete(self, request, *args, **kwargs):
# 쿠키에서 JWT 삭제
response = Response(status=status.HTTP_204_NO_CONTENT)
response.delete_cookie(
"access", domain=os.getenv("COOKIE_DOMAIN"), path="/"
"hunsu_access", domain=os.getenv("COOKIE_DOMAIN"), path="/"
)
response.delete_cookie(
"refresh", domain=os.getenv("COOKIE_DOMAIN"), path="/"
"hunsu_refresh", domain=os.getenv("COOKIE_DOMAIN"), path="/"
)

logger.info(f"User {user.email} deleted successfully")
Expand Down
18 changes: 0 additions & 18 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,6 @@ services:
networks:
- app_network

jenkins:
build:
context: .
dockerfile: Dockerfile.jenkins
image: jenkins/jenkins:lts
user: root # Docker 소켓 접근을 위해 root 사용자로 실행
ports:
- "8080:8080"
- "50000:50000"
volumes:
- /var/run/docker.sock:/var/run/docker.sock # Docker 소켓 공유
- jenkins_home:/var/jenkins_home
networks:
- app_network

locust:
image: locustio/locust
ports:
Expand All @@ -55,8 +40,5 @@ services:
networks:
- app_network

volumes:
jenkins_home:

networks:
app_network:

0 comments on commit f2e18ea

Please sign in to comment.