27 KisAuth(net::io_context& ioc, ssl::context& ctx,
const KisConfig& config) : ioc_(ioc), ctx_(ctx), req_(config) {}
40 std::lock_guard<std::mutex> lock(mtx_);
41 if (!rest_resp_.valid()) {
44 return rest_resp_.access_token_;
54 std::lock_guard<std::mutex> lock(mtx_);
55 if (!ws_resp_.valid()) {
58 return ws_resp_.approval_key_;
62 net::io_context& ioc_;
72 auto response = rest.post(
"/oauth2/tokenP", jsonbody, {{
"content-type",
"application/json"}});
73 if (response.result_int() < 200 || response.result_int() >= 300) {
74 throw std::runtime_error(
"Token authentication failed with HTTP status " + std::to_string(response.result_int()));
76 const std::string resp = std::move(response.body());
77 boost::system::error_code ec;
78 const auto jv = json::parse(resp, ec);
88 if (ec || !jv.is_object()) {
90 throw std::runtime_error(
91 "Token authentication failed: the reply is not a JSON object (" + std::to_string(resp.size()) +
" bytes)"
94 rest_resp_.from_json(jv.as_object());
97 void refreshWebsocket() {
98 const std::string jsonbody = req_.ws_to_jsonbody();
99 KisHttpClient rest(ioc_, ctx_, req_.rest_host(), req_.rest_port());
103 auto response = rest.post(
"/oauth2/Approval", jsonbody, {{
"content-type",
"utf-8"}});
104 if (response.result_int() < 200 || response.result_int() >= 300) {
105 throw std::runtime_error(
106 "WebSocket authentication failed with HTTP status " + std::to_string(response.result_int())
109 const std::string resp = std::move(response.body());
110 boost::system::error_code ec;
111 const auto jv = json::parse(resp, ec);
118 if (ec || !jv.is_object()) {
120 throw std::runtime_error(
121 "WebSocket authentication failed: the reply is not a JSON object (" + std::to_string(resp.size()) +
" bytes)"
124 ws_resp_.from_json(jv.as_object());