mirror of
https://github.com/matrix-construct/construct
synced 2024-05-29 08:13:46 +02:00
ircd:Ⓜ️:device: Associate access_token to device.
This commit is contained in:
parent
964d6b427f
commit
98a8ca7bf2
|
@ -118,7 +118,13 @@ struct ircd::m::device
|
|||
json::property<name::keys, json::object>,
|
||||
|
||||
/// (s2s) Optional display name for the device.
|
||||
json::property<name::device_display_name, json::string>
|
||||
json::property<name::device_display_name, json::string>,
|
||||
|
||||
/// (internal) The event::id of the access_token in the !tokens room
|
||||
/// issued for this device. This is not exposed to the client or
|
||||
/// federation (with the exception of cluster); though its content
|
||||
/// is not accessible anyway.
|
||||
json::property<name::access_token_id, json::string>
|
||||
>
|
||||
{
|
||||
using closure = std::function<void (const string_view &)>;
|
||||
|
|
|
@ -163,4 +163,5 @@ struct ircd::m::name
|
|||
static constexpr const char *const stream_id {"stream_id"};
|
||||
static constexpr const char *const prev_id {"prev_id"};
|
||||
static constexpr const char *const deleted {"deleted"};
|
||||
static constexpr const char *const access_token_id {"access_token_id"};
|
||||
};
|
||||
|
|
|
@ -142,3 +142,4 @@ constexpr const char *const ircd::m::name::messages;
|
|||
constexpr const char *const ircd::m::name::stream_id;
|
||||
constexpr const char *const ircd::m::name::prev_id;
|
||||
constexpr const char *const ircd::m::name::deleted;
|
||||
constexpr const char *const ircd::m::name::access_token_id;
|
||||
|
|
|
@ -84,18 +84,22 @@ post__login_password(client &client,
|
|||
// Log the user in by issuing an event in the tokens room containing
|
||||
// the generated token. When this call completes without throwing the
|
||||
// access_token will be committed and the user will be logged in.
|
||||
m::send(m::user::tokens, user_id, "ircd.access_token", access_token,
|
||||
const m::event::id::buf access_token_id
|
||||
{
|
||||
{ "ip", string(remote(client)) },
|
||||
{ "device_id", device_id },
|
||||
});
|
||||
m::send(m::user::tokens, user_id, "ircd.access_token", access_token,
|
||||
{
|
||||
{ "ip", string(remote(client)) },
|
||||
{ "device_id", device_id },
|
||||
})
|
||||
};
|
||||
|
||||
m::device::set(user_id,
|
||||
{
|
||||
{ "device_id", device_id },
|
||||
{ "display_name", initial_device_display_name },
|
||||
{ "last_seen_ts", ircd::time<milliseconds>() },
|
||||
{ "last_seen_ip", string(remote(client)) },
|
||||
{ "device_id", device_id },
|
||||
{ "display_name", initial_device_display_name },
|
||||
{ "last_seen_ts", ircd::time<milliseconds>() },
|
||||
{ "last_seen_ip", string(remote(client)) },
|
||||
{ "access_token_id", access_token_id },
|
||||
});
|
||||
|
||||
// Send response to user
|
||||
|
|
|
@ -312,20 +312,25 @@ register_user(const m::registar &request,
|
|||
// the generated token. When this call completes without throwing the
|
||||
// access_token will be committed and the user will be logged in.
|
||||
if(gen_token)
|
||||
m::send(m::user::tokens, user_id, "ircd.access_token", access_token,
|
||||
{
|
||||
const m::event::id::buf access_token_id
|
||||
{
|
||||
{ "ip", client? string(remote(*client)) : std::string{} },
|
||||
{ "device", device_id },
|
||||
});
|
||||
m::send(m::user::tokens, user_id, "ircd.access_token", access_token,
|
||||
{
|
||||
{ "ip", client? string(remote(*client)) : std::string{} },
|
||||
{ "device", device_id },
|
||||
})
|
||||
};
|
||||
|
||||
if(gen_token)
|
||||
m::device::set(user_id,
|
||||
{
|
||||
{ "device_id", device_id },
|
||||
{ "display_name", initial_device_display_name },
|
||||
{ "last_seen_ts", ircd::time<milliseconds>() },
|
||||
{ "last_seen_ip", string(remote(*client)) },
|
||||
{ "device_id", device_id },
|
||||
{ "display_name", initial_device_display_name },
|
||||
{ "last_seen_ts", ircd::time<milliseconds>() },
|
||||
{ "last_seen_ip", string(remote(*client)) },
|
||||
{ "access_token_id", access_token_id },
|
||||
});
|
||||
}
|
||||
|
||||
// Send response to user
|
||||
return json::strung
|
||||
|
|
Loading…
Reference in a new issue