Commit d0142938 authored by jan.koester's avatar jan.koester
Browse files

test

parent 3102be1a
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -180,7 +180,7 @@ void ClientConnection::reConnect() {
void ClientConnection::setUrl(const libhttppp::HttpUrl& url) {
    _Url = url;
    std::string path = normalize_path(_Url.getPath());
    if (path == "/") path = "/admin/api";
    if (path == "/") path = "/settings/admin/api";
    _RequestPath = path;
    if (_Client) {
        _Client = std::make_unique<libhttppp::HttpClient>(_Url);
@@ -195,7 +195,7 @@ void ClientConnection::setUrl(const std::string& url) {
        path = extract_path_from_url(url);
    }
    path = normalize_path(path);
    if (path == "/") path = "/admin/api";
    if (path == "/") path = "/settings/admin/api";
    _RequestPath = path;
    if (_Client) {
        _Client = std::make_unique<libhttppp::HttpClient>(_Url);
+41 −1
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@

#include "admin.h"
#include "authdb.h"
#include "api.h"
#include "user.h"
#include "group.h"
#include "domain.h"
@@ -2025,6 +2026,45 @@ namespace authdb {
                    return;
                }

                // JSON command API at /settings/admin/api (client library protocol)
                // This endpoint handles its own auth (ClientAuth/UserAuth in JSON body)
                {
                    const std::string &reqUrl = curreq.getRequestURL();
                    if (reqUrl == "/settings/admin/api" || reqUrl == "/settings/admin/api/") {
                        libhttppp::HttpHeader::HeaderData *ct = nullptr;
                        try { ct = curreq.getHeaderData("content-type"); } catch(...) {}
                        bool isJson = false;
                        if (ct && ct->getfirstValue()) {
                            std::string ctval = ct->getfirstValue()->getvalue();
                            isJson = (ctval.find("application/json") != std::string::npos);
                        }
                        if (isJson) {
                            try {
                                ::uuid::uuid adminDid;
                                AuthBackend::Guard guard(_AdminBackend, AuthBackend::Shared);
                                ApiController(_AdminBackend, adminDid, curreq, tid, args);
                            } catch (AuthBackendError &e) {
                                json_object *jerr = json_object_new_array();
                                json_object *eobj = json_object_new_object();
                                json_object_object_add(eobj, "error", json_object_new_string(e.what()));
                                json_object_array_add(jerr, eobj);
                                const char *errstr = json_object_to_json_string(jerr);
                                libhttppp::HttpResponse rep;
                                rep.setState(HTTP500);
                                rep.setContentType("application/json");
                                rep.send(curreq, errstr, strlen(errstr));
                                json_object_put(jerr);
                            } catch (std::exception &e) {
                                libhttppp::HttpResponse rep;
                                rep.setState(HTTP500);
                                rep.setContentType("application/json");
                                rep.send(curreq, "[{\"error\":\"internal error\"}]", 28);
                            }
                            return;
                        }
                    }
                }

                if (!sdat) {
                    throw AuthBackendError("No Session found!");
                }
@@ -2105,7 +2145,7 @@ namespace authdb {
                }
            }

            // ---- Route API requests ----
            // ---- Route REST API requests ----
            const std::string &url = curreq.getRequestURL();
            char domain[255] = {}, apiurl[255] = {}, param[255] = {};