Skip to content

Commit

Permalink
Support registration token UIA type
Browse files Browse the repository at this point in the history
  • Loading branch information
govynnus committed Jul 19, 2021
1 parent 1c277e9 commit f785a41
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/mtx/user_interactive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -181,6 +183,13 @@ struct MSISDN
std::vector<ThreePIDCred> 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
{};
Expand Down Expand Up @@ -214,6 +223,7 @@ struct Auth
auth::Terms,
auth::SSO,
auth::Dummy,
auth::RegistrationToken,
auth::Fallback>
content;
};
Expand Down
4 changes: 4 additions & 0 deletions lib/structs/user_interactive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &registration_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; },
Expand Down
7 changes: 7 additions & 0 deletions tests/requests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,13 @@ TEST(Requests, UserInteractiveAuth)
],
"session": "<session ID>"
})"_json);

a.content = auth::RegistrationToken{"<token>"};
EXPECT_EQ(nlohmann::json(a), R"({
"type": "org.matrix.msc3231.login.registration_token",
"token": "<token>",
"session": "<session ID>"
})"_json);
}

TEST(Requests, RoomVisibility)
Expand Down

0 comments on commit f785a41

Please sign in to comment.