diff --git a/include/mtx/user_interactive.hpp b/include/mtx/user_interactive.hpp index 008734f39..e334aed8e 100644 --- a/include/mtx/user_interactive.hpp +++ b/include/mtx/user_interactive.hpp @@ -40,6 +40,8 @@ constexpr std::string_view sso = "m.login.sso"; // needed for /login at least constexpr std::string_view dummy = "m.login.dummy"; //! Authentication by accepting a set of terms like a privacy policy. constexpr std::string_view terms = "m.login.terms"; // see MSC1692 +//! Authentication using a registration token. See MSC3231. +constexpr std::string_view registration_token = "org.matrix.msc3231.login.registration_token"; } //! A list of auth types @@ -181,6 +183,13 @@ struct MSISDN std::vector threepidCreds; }; +//! Registration token authentication stage. +struct RegistrationToken +{ + //! The registration token to use + std::string token; +}; + //! OAuth2, client retries with the session only, so I'm guessing this is empty? struct OAuth2 {}; @@ -214,6 +223,7 @@ struct Auth auth::Terms, auth::SSO, auth::Dummy, + auth::RegistrationToken, auth::Fallback> content; }; diff --git a/lib/structs/user_interactive.cpp b/lib/structs/user_interactive.cpp index af6861065..e3b18fea6 100644 --- a/lib/structs/user_interactive.cpp +++ b/lib/structs/user_interactive.cpp @@ -117,6 +117,10 @@ to_json(nlohmann::json &obj, const Auth &auth) obj["type"] = auth_types::msisdn; obj["threepidCreds"] = id.threepidCreds; }, + [&obj](const auth::RegistrationToken ®istration_token) { + obj["type"] = auth_types::registration_token; + obj["token"] = registration_token.token; + }, [&obj](const auth::OAuth2 &) { obj["type"] = auth_types::oauth2; }, [&obj](const auth::SSO &) { obj["type"] = auth_types::sso; }, [&obj](const auth::Terms &) { obj["type"] = auth_types::terms; }, diff --git a/tests/requests.cpp b/tests/requests.cpp index fa24be3ac..1e491b023 100644 --- a/tests/requests.cpp +++ b/tests/requests.cpp @@ -281,6 +281,13 @@ TEST(Requests, UserInteractiveAuth) ], "session": "" })"_json); + + a.content = auth::RegistrationToken{""}; + EXPECT_EQ(nlohmann::json(a), R"({ + "type": "org.matrix.msc3231.login.registration_token", + "token": "", + "session": "" +})"_json); } TEST(Requests, RoomVisibility)