Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support registration token UIA type #60

Merged
merged 1 commit into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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