diff --git a/docs_src/security/tutorial004.py b/docs_src/security/tutorial004.py index 130dc699a..a03597c1b 100644 --- a/docs_src/security/tutorial004.py +++ b/docs_src/security/tutorial004.py @@ -1,3 +1,4 @@ +import os from datetime import datetime, timedelta, timezone from typing import Union @@ -82,7 +83,10 @@ def create_access_token(data: dict, expires_delta: Union[timedelta, None] = None expire = datetime.now(timezone.utc) + expires_delta else: expire = datetime.now(timezone.utc) + timedelta(minutes=15) - to_encode.update({"exp": expire}) +SECRET_KEY = os.getenv("SECRET_KEY", "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7") # WARNING: Use environment variable in production +# openssl rand -hex 32 +# In production, use environment variables for secrets! +SECRET_KEY = os.getenv("SECRET_KEY", "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7") # Demo fallback - DO NOT use in production encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM) return encoded_jwt