From 34a2a660272c4501d96276acc2b19e4251b3f87f Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 14 Jul 2023 19:09:00 +0200 Subject: [PATCH] Fix boring login API expecting a weird form/multiparam thing instead of classic JSON for credentials ... --- moulinette/interfaces/api.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/moulinette/interfaces/api.py b/moulinette/interfaces/api.py index 34b51143..bf3b0c7f 100644 --- a/moulinette/interfaces/api.py +++ b/moulinette/interfaces/api.py @@ -353,11 +353,18 @@ def login(self): """ - if "credentials" not in request.params: - raise HTTPResponse("Missing credentials parameter", 400) - credentials = request.params["credentials"] + if request.get_header("Content-Type") == "application/json": + if "credentials" not in request.json: + raise HTTPResponse("Missing credentials parameter", 400) + credentials = request.json["credentials"] + profile = request.json.get("profile", self.actionsmap.default_authentication) + else: + if "credentials" not in request.params: + raise HTTPResponse("Missing credentials parameter", 400) + credentials = request.params["credentials"] + + profile = request.params.get("profile", self.actionsmap.default_authentication) - profile = request.params.get("profile", self.actionsmap.default_authentication) authenticator = self.actionsmap.get_authenticator(profile) try: @@ -732,7 +739,7 @@ def api18n(callback): def wrapper(*args, **kwargs): try: locale = request.params.pop("locale") - except KeyError: + except (KeyError, ValueError): locale = m18n.default_locale m18n.set_locale(locale) return callback(*args, **kwargs)