chore: jwt_secret_key is guaranteed to be in the schema now

This commit is contained in:
Matthias
2026-02-10 20:33:39 +01:00
parent 6e38759bd1
commit eec33190d2

View File

@@ -15,6 +15,7 @@ from freqtrade.rpc.api_server.deps import get_api_config
logger = logging.getLogger(__name__)
ALGORITHM = "HS256"
__DEFAULT_JWT = "somethingRandomSomethingRandom123"
router_login = APIRouter()
@@ -59,7 +60,7 @@ async def validate_ws_token(
api_config: dict[str, Any] = Depends(get_api_config),
):
secret_ws_token = api_config.get("ws_token", None)
secret_jwt_key = api_config.get("jwt_secret_key", "super-secret")
secret_jwt_key = api_config["jwt_secret_key"]
# Check if ws_token is/in secret_ws_token
if ws_token and secret_ws_token:
@@ -111,7 +112,7 @@ def http_basic_or_jwt_token(
api_config=Depends(get_api_config),
):
if token:
return get_user_from_token(token, api_config.get("jwt_secret_key", "super-secret"))
return get_user_from_token(token, api_config["jwt_secret_key"])
elif form_data and verify_auth(api_config, form_data.username, form_data.password):
return form_data.username
@@ -129,12 +130,12 @@ def token_login(
token_data = {"identity": {"u": form_data.username}}
access_token = create_token(
token_data,
api_config.get("jwt_secret_key", "super-secret"),
api_config["jwt_secret_key"],
token_type="access", # noqa: S106
)
refresh_token = create_token(
token_data,
api_config.get("jwt_secret_key", "super-secret"),
api_config["jwt_secret_key"],
token_type="refresh", # noqa: S106
)
return {
@@ -151,11 +152,11 @@ def token_login(
@router_login.post("/token/refresh", response_model=AccessToken)
def token_refresh(token: str = Depends(oauth2_scheme), api_config=Depends(get_api_config)):
# Refresh token
u = get_user_from_token(token, api_config.get("jwt_secret_key", "super-secret"), "refresh")
u = get_user_from_token(token, api_config["jwt_secret_key"], "refresh")
token_data = {"identity": {"u": u}}
access_token = create_token(
token_data,
api_config.get("jwt_secret_key", "super-secret"),
api_config["jwt_secret_key"],
token_type="access", # noqa: S106
)
return {"access_token": access_token}