Files
msa-django-blog/blog/utils.py

13 lines
677 B
Python

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)}")