mirror of
https://github.com/matrix-construct/construct
synced 2024-11-16 15:00:51 +01:00
modules/m_device: Hook device deletion to delete associated access_token.
This commit is contained in:
parent
98a8ca7bf2
commit
82c2b7248a
1 changed files with 46 additions and 0 deletions
|
@ -8,6 +8,12 @@
|
||||||
// copyright notice and this permission notice is present in all copies. The
|
// copyright notice and this permission notice is present in all copies. The
|
||||||
// full license for this software is available in the LICENSE file.
|
// full license for this software is available in the LICENSE file.
|
||||||
|
|
||||||
|
namespace ircd::m
|
||||||
|
{
|
||||||
|
extern hookfn<vm::eval &> _access_token_delete_hook;
|
||||||
|
static void _access_token_delete(const m::event &event, m::vm::eval &eval);
|
||||||
|
}
|
||||||
|
|
||||||
ircd::mapi::header
|
ircd::mapi::header
|
||||||
IRCD_MODULE
|
IRCD_MODULE
|
||||||
{
|
{
|
||||||
|
@ -83,6 +89,46 @@ ircd::m::device::del(const m::user &user,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Deletes the access_token associated with a device when the device
|
||||||
|
/// (specifically the access_token_id property of that device) is deleted.
|
||||||
|
decltype(ircd::m::_access_token_delete_hook)
|
||||||
|
ircd::m::_access_token_delete_hook
|
||||||
|
{
|
||||||
|
_access_token_delete,
|
||||||
|
{
|
||||||
|
{ "_site", "vm.effect" },
|
||||||
|
{ "type", "m.room.redaction" },
|
||||||
|
{ "origin", my_host() },
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
ircd::m::_access_token_delete(const m::event &event,
|
||||||
|
m::vm::eval &eval)
|
||||||
|
{
|
||||||
|
const auto &target(json::get<"redacts"_>(event));
|
||||||
|
if(!target)
|
||||||
|
return;
|
||||||
|
|
||||||
|
char buf[std::max(m::event::TYPE_MAX_SIZE, m::id::MAX_SIZE)];
|
||||||
|
if(m::get(std::nothrow, target, "type", buf) != "ircd.device.access_token_id"_sv)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(m::get(std::nothrow, target, "sender", buf) != at<"sender"_>(event))
|
||||||
|
return;
|
||||||
|
|
||||||
|
m::get(std::nothrow, target, "content", [&event, &target, &buf]
|
||||||
|
(const json::object &content)
|
||||||
|
{
|
||||||
|
const event::id &token_event_id
|
||||||
|
{
|
||||||
|
unquote(content.at(""))
|
||||||
|
};
|
||||||
|
|
||||||
|
m::redact(m::user::tokens, at<"sender"_>(event), token_event_id, "device deleted");
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
bool
|
bool
|
||||||
IRCD_MODULE_EXPORT
|
IRCD_MODULE_EXPORT
|
||||||
ircd::m::device::has(const m::user &user,
|
ircd::m::device::has(const m::user &user,
|
||||||
|
|
Loading…
Reference in a new issue