You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516
  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(to_encode, settings.SECRET_KEY, algorithm=settings.ALGORITHM)
  13. return encoded_jwt