게시물 등록 및 토큰검증 후 등록 추가

This commit is contained in:
2025-04-22 18:40:48 +09:00
parent 72a59cc924
commit 5421723a54
19 changed files with 384 additions and 0 deletions

13
blog/utils.py Normal file
View File

@ -0,0 +1,13 @@
import requests
from rest_framework.exceptions import AuthenticationFailed
def verify_token_with_auth_server(token: str):
# url = "http://192.168.0.202:8000/api/auth/verify/"
url = settings.AUTH_VERIFY_URL # ✅ .env에서 설정한 값 사용
headers = {"Content-Type": "application/json"}
try:
response = requests.post(url, json={"token": token}, headers=headers, timeout=3)
if response.status_code != 200:
raise AuthenticationFailed("유효하지 않은 토큰입니다 (auth 서버 응답 오류)")
except requests.exceptions.RequestException as e:
raise AuthenticationFailed(f"auth 서버 통신 실패: {str(e)}")