25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718
  1. from datetime import datetime, timedelta
  2. from typing import Optional
  3. from jose import jwt
  4. from core.config import settings
  5. def create_access_token(data: dict, expires_delta: Optional[timedelta] = None):
  6. to_encode = data.copy()
  7. if expires_delta:
  8. expire = datetime.utcnow() + expires_delta
  9. else:
  10. expire = datetime.utcnow() + timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE)
  11. to_encode.update({"exp": expire})
  12. encoded_jwt = jwt.encode(
  13. to_encode, settings.SECRET_KEY, algorithm=settings.ALGORITHM
  14. )
  15. return encoded_jwt