2018-02-03 18:22:01 -08:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
2017-08-23 15:10:28 -06:00
|
|
|
|
|
|
|
using namespace ircd;
|
|
|
|
|
2019-09-28 16:12:07 -07:00
|
|
|
static m::resource::response
|
2019-02-18 11:22:45 -08:00
|
|
|
post__logout(client &,
|
2019-09-28 16:12:07 -07:00
|
|
|
const m::resource::request &);
|
2019-02-18 11:22:45 -08:00
|
|
|
|
2019-09-28 16:12:07 -07:00
|
|
|
static m::resource::response
|
2019-02-18 11:22:45 -08:00
|
|
|
post__logout_all(client &,
|
2019-09-28 16:12:07 -07:00
|
|
|
const m::resource::request &);
|
2019-02-18 11:22:45 -08:00
|
|
|
|
2018-02-15 13:06:49 -08:00
|
|
|
mapi::header
|
|
|
|
IRCD_MODULE
|
|
|
|
{
|
|
|
|
"Client 3.3.2 :Logout"
|
|
|
|
};
|
|
|
|
|
2019-09-28 16:12:07 -07:00
|
|
|
m::resource
|
2018-02-15 13:06:49 -08:00
|
|
|
logout_resource
|
2017-08-23 15:10:28 -06:00
|
|
|
{
|
2017-10-11 20:52:33 -07:00
|
|
|
"/_matrix/client/r0/logout",
|
2017-12-12 13:26:39 -07:00
|
|
|
{
|
2018-02-15 13:06:49 -08:00
|
|
|
"(3.3.2) Invalidates an existing access token, so that it can no"
|
|
|
|
" longer be used for authorization."
|
2017-12-12 13:26:39 -07:00
|
|
|
}
|
2017-08-23 15:10:28 -06:00
|
|
|
};
|
|
|
|
|
2019-09-28 16:12:07 -07:00
|
|
|
m::resource
|
2019-02-18 11:22:45 -08:00
|
|
|
logout_all_resource
|
|
|
|
{
|
|
|
|
"/_matrix/client/r0/logout/all",
|
|
|
|
{
|
|
|
|
"(5.4.4) Invalidates all access tokens for a user, so that they can no"
|
|
|
|
" longer be used for authorization. This includes the access token"
|
|
|
|
" that made this request."
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-09-28 16:12:07 -07:00
|
|
|
m::resource::method
|
2019-02-18 11:22:45 -08:00
|
|
|
post_method
|
|
|
|
{
|
|
|
|
logout_resource, "POST", post__logout,
|
|
|
|
{
|
|
|
|
post_method.REQUIRES_AUTH
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-09-28 16:12:07 -07:00
|
|
|
m::resource::method
|
2019-02-18 11:22:45 -08:00
|
|
|
post_all_method
|
|
|
|
{
|
|
|
|
logout_all_resource, "POST", post__logout_all,
|
|
|
|
{
|
|
|
|
post_all_method.REQUIRES_AUTH
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-09-28 16:12:07 -07:00
|
|
|
m::resource::response
|
2019-02-18 11:22:45 -08:00
|
|
|
post__logout(client &client,
|
2019-09-28 16:12:07 -07:00
|
|
|
const m::resource::request &request)
|
2017-08-23 15:10:28 -06:00
|
|
|
{
|
2017-09-24 18:05:42 -07:00
|
|
|
const auto &access_token
|
|
|
|
{
|
2018-03-02 02:14:00 -08:00
|
|
|
request.access_token
|
2017-09-24 18:05:42 -07:00
|
|
|
};
|
2017-08-23 15:10:28 -06:00
|
|
|
|
2020-04-01 17:14:51 -07:00
|
|
|
const m::user::tokens tokens
|
2019-02-18 11:04:11 -08:00
|
|
|
{
|
2020-04-01 17:14:51 -07:00
|
|
|
request.user_id
|
2019-02-18 11:04:11 -08:00
|
|
|
};
|
|
|
|
|
2020-04-01 17:14:51 -07:00
|
|
|
const bool deleted
|
2019-02-18 11:04:11 -08:00
|
|
|
{
|
2020-04-01 17:14:51 -07:00
|
|
|
tokens.del(access_token, "client logout")
|
2019-02-18 11:04:11 -08:00
|
|
|
};
|
|
|
|
|
2019-09-28 16:12:07 -07:00
|
|
|
return m::resource::response
|
2019-02-18 11:04:11 -08:00
|
|
|
{
|
2019-02-18 11:22:45 -08:00
|
|
|
client, http::OK
|
2019-02-18 11:04:11 -08:00
|
|
|
};
|
2019-02-18 11:22:45 -08:00
|
|
|
}
|
2019-02-18 11:04:11 -08:00
|
|
|
|
2019-09-28 16:12:07 -07:00
|
|
|
m::resource::response
|
2019-02-18 11:22:45 -08:00
|
|
|
post__logout_all(client &client,
|
2019-09-28 16:12:07 -07:00
|
|
|
const m::resource::request &request)
|
2019-02-18 11:22:45 -08:00
|
|
|
{
|
2020-04-01 17:14:51 -07:00
|
|
|
const m::user::tokens tokens
|
2019-09-30 20:50:58 -07:00
|
|
|
{
|
2020-04-01 17:14:51 -07:00
|
|
|
request.user_id
|
2019-09-30 20:50:58 -07:00
|
|
|
};
|
|
|
|
|
2020-04-01 17:14:51 -07:00
|
|
|
const size_t invalidations
|
2019-02-18 11:22:45 -08:00
|
|
|
{
|
2020-04-01 17:14:51 -07:00
|
|
|
tokens.del("client logout all")
|
2019-02-18 11:22:45 -08:00
|
|
|
};
|
|
|
|
|
2019-09-28 16:12:07 -07:00
|
|
|
return m::resource::response
|
2019-02-18 11:22:45 -08:00
|
|
|
{
|
|
|
|
client, json::members
|
|
|
|
{
|
2020-04-01 17:14:51 -07:00
|
|
|
{ "invalidations", long(invalidations) }
|
2019-02-18 11:22:45 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|