Skip to content
Snippets Groups Projects
Commit b3f0ce0a authored by Callum Brown's avatar Callum Brown
Browse files

Support registration token validity checking

parent deb51ef1
No related branches found
No related tags found
No related merge requests found
Pipeline #1606 passed
......@@ -31,5 +31,17 @@ struct Register
void
from_json(const nlohmann::json &obj, Register &response);
//! Response from the `GET
//! /_matrix/client/unstable/org.matrix.msc3231/register/org.matrix.msc3231.login.registration_token/validity`
//! endpoint.
struct RegistrationTokenValidity
{
//! Whether the registration token is valid or not
bool valid;
};
void
from_json(const nlohmann::json &obj, RegistrationTokenValidity &response);
}
}
......@@ -70,6 +70,7 @@ struct Notifications;
struct Profile;
struct QueryKeys;
struct Register;
struct RegistrationTokenValidity;
struct Sync;
struct TurnServer;
struct UploadKeys;
......@@ -241,6 +242,10 @@ public:
const user_interactive::Auth &auth,
Callback<mtx::responses::Register> cb);
//! Check the validity of a registration token
void registration_token_validity(const std::string token,
Callback<mtx::responses::RegistrationTokenValidity> cb);
//! Paginate through the list of events that the user has been,
//! or would have been notified about.
void notifications(uint64_t limit,
......
......@@ -890,6 +890,21 @@ Client::registration(const std::string &user,
post<nlohmann::json, mtx::responses::Register>("/client/r0/register", req, callback, false);
}
void
Client::registration_token_validity(const std::string token,
Callback<mtx::responses::RegistrationTokenValidity> cb)
{
const auto api_path = "/client/unstable/org.matrix.msc3231/register/"
"org.matrix.msc3231.login.registration_token/validity?" +
mtx::client::utils::query_params({{"token", token}});
get<mtx::responses::RegistrationTokenValidity>(
api_path,
[cb](const mtx::responses::RegistrationTokenValidity &res, HeaderFields, RequestErr err) {
cb(res, err);
});
}
void
Client::send_state_event(const std::string &room_id,
const std::string &event_type,
......
......@@ -15,5 +15,11 @@ from_json(const json &obj, Register &response)
response.access_token = obj.at("access_token").get<std::string>();
response.device_id = obj.at("device_id").get<std::string>();
}
void
from_json(const nlohmann::json &obj, RegistrationTokenValidity &response)
{
response.valid = obj.at("valid").get<bool>();
}
}
}
......@@ -476,6 +476,14 @@ TEST(Responses, WellKnown)
EXPECT_EQ(wellknown.identity_server->base_url, "https://identity.example.com");
}
TEST(Responses, RegistrationTokenValidity)
{
json data = R"({"valid" : true})"_json;
RegistrationTokenValidity validity = data;
EXPECT_EQ(validity.valid, true);
}
TEST(Responses, CreateRoom)
{
json data = R"({"room_id" : "!sefiuhWgwghwWgh:example.com"})"_json;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment