diff --git a/include/mtx/user_interactive.hpp b/include/mtx/user_interactive.hpp index 9c113222a906cf85e4012bad009e39700d0332e5..0d52f4cc78173de0c48b88fdcbc5f4f5f8db5d9e 100644 --- a/include/mtx/user_interactive.hpp +++ b/include/mtx/user_interactive.hpp @@ -142,6 +142,8 @@ struct Terms {}; struct Dummy {}; +struct Fallback +{}; } struct Auth { @@ -156,7 +158,8 @@ struct Auth auth::MSISDN, auth::OAuth2, auth::Terms, - auth::Dummy> + auth::Dummy, + auth::Fallback> content; }; void diff --git a/lib/structs/errors.cpp b/lib/structs/errors.cpp index 42940151a4f413c7390be672b95eae47bb5b04c3..5d9fa2c094c81c2babc2d4fad9284efb845b78bf 100644 --- a/lib/structs/errors.cpp +++ b/lib/structs/errors.cpp @@ -84,7 +84,7 @@ from_string(const std::string &code) void from_json(const nlohmann::json &obj, Error &error) { - error.errcode = from_string(obj.at("errcode").get<std::string>()); + error.errcode = from_string(obj.value("errcode", "")); error.error = obj.value("error", ""); if (obj.contains("session")) diff --git a/lib/structs/user_interactive.cpp b/lib/structs/user_interactive.cpp index c63933c9501c57ce786ab899b33b750d7d7f56f6..17df7770c751b47977b5183d8b66f487698121d8 100644 --- a/lib/structs/user_interactive.cpp +++ b/lib/structs/user_interactive.cpp @@ -118,6 +118,7 @@ to_json(nlohmann::json &obj, const Auth &auth) [&obj](const auth::OAuth2 &) { obj["type"] = auth_types::oauth2; }, [&obj](const auth::Terms &) { obj["type"] = auth_types::terms; }, [&obj](const auth::Dummy &) { obj["type"] = auth_types::dummy; }, + [&obj](const auth::Fallback &) {}, }, auth.content); } diff --git a/tests/requests.cpp b/tests/requests.cpp index 1b52c68daca53c67d4fab7179894a7f99a29f25a..ad4b181e64dba2342ef3f401d33adde727b545f8 100644 --- a/tests/requests.cpp +++ b/tests/requests.cpp @@ -223,6 +223,10 @@ TEST(Requests, UserInteractiveAuth) "type": "m.login.dummy", "session": "<session ID>" })"_json); + a.content = auth::Fallback{}; + EXPECT_EQ(nlohmann::json(a), R"({ + "session": "<session ID>" +})"_json); a.content = auth::EmailIdentity{{ {"<identity server session id>",