Start by renaming variables to something more generic. This will give us a bit more flexibility as we look to other session management mechanisms.

This commit is contained in:
Tim Farrell 2024-02-01 13:40:59 -06:00
parent b2fae0643e
commit d67f3d982b
4 changed files with 11 additions and 7 deletions

View file

@ -25,7 +25,7 @@ ENV OLLAMA_API_BASE_URL "/ollama/api"
ENV OPENAI_API_BASE_URL "" ENV OPENAI_API_BASE_URL ""
ENV OPENAI_API_KEY "" ENV OPENAI_API_KEY ""
ENV WEBUI_JWT_SECRET_KEY "SECRET_KEY" ENV WEBUI_SECRET_KEY ""
WORKDIR /app/backend WORKDIR /app/backend

View file

@ -98,12 +98,15 @@ WEBUI_VERSION = os.environ.get("WEBUI_VERSION", "v1.0.0-alpha.61")
WEBUI_AUTH = True WEBUI_AUTH = True
#################################### ####################################
# WEBUI_JWT_SECRET_KEY # WEBUI_SECRET_KEY
#################################### ####################################
WEBUI_JWT_SECRET_KEY = os.environ.get("WEBUI_JWT_SECRET_KEY", "t0p-s3cr3t") WEBUI_SECRET_KEY = os.environ.get(
"WEBUI_SECRET_KEY",
os.environ.get("WEBUI_JWT_SECRET_KEY", "t0p-s3cr3t") # DEPRECATED: remove at next major version
)
if WEBUI_AUTH and WEBUI_JWT_SECRET_KEY == "": if WEBUI_AUTH and WEBUI_SECRET_KEY == "":
raise ValueError(ERROR_MESSAGES.ENV_VAR_NOT_FOUND) raise ValueError(ERROR_MESSAGES.ENV_VAR_NOT_FOUND)
#################################### ####################################

View file

@ -14,7 +14,7 @@ import config
logging.getLogger("passlib").setLevel(logging.ERROR) logging.getLogger("passlib").setLevel(logging.ERROR)
JWT_SECRET_KEY = config.WEBUI_JWT_SECRET_KEY SESSION_SECRET = config.WEBUI_SECRET_KEY
ALGORITHM = "HS256" ALGORITHM = "HS256"
############## ##############
@ -42,13 +42,13 @@ def create_token(data: dict, expires_delta: Union[timedelta, None] = None) -> st
expire = datetime.utcnow() + expires_delta expire = datetime.utcnow() + expires_delta
payload.update({"exp": expire}) payload.update({"exp": expire})
encoded_jwt = jwt.encode(payload, JWT_SECRET_KEY, algorithm=ALGORITHM) encoded_jwt = jwt.encode(payload, SESSION_SECRET, algorithm=ALGORITHM)
return encoded_jwt return encoded_jwt
def decode_token(token: str) -> Optional[dict]: def decode_token(token: str) -> Optional[dict]:
try: try:
decoded = jwt.decode(token, JWT_SECRET_KEY, options={"verify_signature": False}) decoded = jwt.decode(token, SESSION_SECRET, options={"verify_signature": False})
return decoded return decoded
except Exception as e: except Exception as e:
return None return None

View file

@ -26,6 +26,7 @@ services:
- ${OLLAMA_WEBUI_PORT-3000}:8080 - ${OLLAMA_WEBUI_PORT-3000}:8080
environment: environment:
- 'OLLAMA_API_BASE_URL=http://ollama:11434/api' - 'OLLAMA_API_BASE_URL=http://ollama:11434/api'
- 'WEBUI_SECRET_KEY='
extra_hosts: extra_hosts:
- host.docker.internal:host-gateway - host.docker.internal:host-gateway
restart: unless-stopped restart: unless-stopped