From 19e09b0ad565761ba8ca6ea31de3515e38bc7082 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 4 Mar 2019 13:12:53 -0800 Subject: [PATCH] ircd::m::login: Support identifier typed login. --- include/ircd/m/login.h | 3 +++ include/ircd/m/name.h | 1 + ircd/m_name.cc | 1 + modules/client/login.cc | 25 ++++++++++++++++++++++++- 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/include/ircd/m/login.h b/include/ircd/m/login.h index 28467d973..3ef315e77 100644 --- a/include/ircd/m/login.h +++ b/include/ircd/m/login.h @@ -23,6 +23,9 @@ struct ircd::m::login /// "m.login.token"] json::property, + /// Identification information for the user. + json::property, + /// The fully qualified user ID or just local part of the user ID, to /// log in. json::property, diff --git a/include/ircd/m/name.h b/include/ircd/m/name.h index 9288c4a13..e94842a7e 100644 --- a/include/ircd/m/name.h +++ b/include/ircd/m/name.h @@ -115,6 +115,7 @@ struct ircd::m::name static constexpr const char *const token {"token"}; static constexpr const char *const device_id {"device_id"}; static constexpr const char *const initial_device_display_name {"initial_device_display_name"}; + static constexpr const char *const identifier {"identifier"}; static constexpr const char *const username {"username"}; static constexpr const char *const bind_email {"bind_email"}; diff --git a/ircd/m_name.cc b/ircd/m_name.cc index ee309be48..87ef8af67 100644 --- a/ircd/m_name.cc +++ b/ircd/m_name.cc @@ -94,6 +94,7 @@ constexpr const char *const ircd::m::name::password; constexpr const char *const ircd::m::name::token; constexpr const char *const ircd::m::name::device_id; constexpr const char *const ircd::m::name::initial_device_display_name; +constexpr const char *const ircd::m::name::identifier; constexpr const char *const ircd::m::name::username; constexpr const char *const ircd::m::name::bind_email; diff --git a/modules/client/login.cc b/modules/client/login.cc index 7955b74ba..21118bf7d 100644 --- a/modules/client/login.cc +++ b/modules/client/login.cc @@ -30,10 +30,33 @@ resource::response post__login_password(client &client, const resource::request::object &request) { + const json::object &identifier + { + json::get<"identifier"_>(request) + }; + + const json::string &identifier_type + { + identifier.get("type") + }; + + if(identifier_type && identifier_type != "m.id.user") + throw m::UNSUPPORTED + { + "Identifier type '%s' is not supported.", identifier_type + }; + + const json::string &username + { + identifier_type == "m.id.user"? + json::string(identifier.at("user")): + at<"user"_>(request) + }; + // Build a canonical MXID from a the user field const m::id::user::buf user_id { - at<"user"_>(request), my_host() + username, my_host() }; const string_view &supplied_password