diff --git a/include/ircd/m/user/tokens.h b/include/ircd/m/user/tokens.h index 2fef9b37f..3c9f455c9 100644 --- a/include/ircd/m/user/tokens.h +++ b/include/ircd/m/user/tokens.h @@ -28,6 +28,8 @@ struct ircd::m::user::tokens bool check(const string_view &token) const; bool del(const string_view &token, const string_view &reason) const; size_t del(const string_view &reason) const; + m::event::id::buf add(const string_view &, const json::object & = {}) const; + string_view create(const mutable_buffer &, const json::object & = {}) const; tokens(const m::user &user) :user{user} diff --git a/matrix/user_tokens.cc b/matrix/user_tokens.cc index fa3b3522d..add4bd8c4 100644 --- a/matrix/user_tokens.cc +++ b/matrix/user_tokens.cc @@ -8,6 +8,42 @@ // copyright notice and this permission notice is present in all copies. The // full license for this software is available in the LICENSE file. +ircd::string_view +ircd::m::user::tokens::create(const mutable_buffer &buf, + const json::object &content) +const +{ + const auto token + { + generate(buf) + }; + + const auto event_id + { + add(token, content) + }; + + return token; +} + +ircd::m::event::id::buf +ircd::m::user::tokens::add(const string_view &token, + const json::object &content) +const +{ + const m::room::id::buf tokens_room + { + "tokens", user.user_id.host() + }; + + const m::event::id::buf event_id + { + m::send(tokens_room, user, "ircd.access_token", token, content) + }; + + return event_id; +} + size_t ircd::m::user::tokens::del(const string_view &reason) const