diff --git a/CMakeLists.txt b/CMakeLists.txt index edd1fc8..9b7edf2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,7 @@ add_definitions(-DCONFIG_DIR="${CONFIG_DIR}" add_module(HOST_META) add_module(WEBFINGER) add_module(ACTIVITYPUB) +add_module(OAUTH) # General includes include(CTest) @@ -107,6 +108,7 @@ target_link_libraries(wormhole wormhole_lib wormhole_webfinger_module wormhole_activitypub_module wormhole_host_meta_module + wormhole_oauth_module ${CMAKE_DL_LIBS} ${LIBMICROHTTPD_LIBRARIES} ${SQLite3_LIBRARIES} diff --git a/src/main.cpp b/src/main.cpp index faf6769..b16f327 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,27 +31,36 @@ #include "route_args.h" // Compile-time modules + +/* Each module needs to be loaded via the /CMakeLists.txt file, + and as such, the module header must exist and be defined */ #ifdef MODULE_WEBFINGER #include "protocol/webfinger/webfinger.h" -#endif +#endif // MODULE_WEBFINGER #ifdef MODULE_ACTIVITYPUB #include "protocol/activitypub/activitypub.h" -#endif +#endif // MODULE_ACTIVITYPUB #ifdef MODULE_HOST_META #include "protocol/host-meta/hostmeta.h" -#endif +#endif // MODULE_HOST_META +#ifdef MODULE_OAUTH +#include "protocol/oauth/oauth.h" +#endif // MODULE_OAUTH void init_routes(const std::unique_ptr& server) { #ifdef MODULE_WEBFINGER Protocol::Webfinger::init_webfinger(server.get()); -#endif +#endif // MODULE_WEBFINGER #ifdef MODULE_ACTIVITYPUB Protocol::ActivityPub::init_activitypub(server.get()); -#endif +#endif // MODULE_ACTIVITYPUB #ifdef MODULE_HOST_META Protocol::HostMeta::init_host_meta(server.get()); -#endif +#endif // MODULE_HOST_META +#ifdef MODULE_OAUTH + Protocol::OAuth::init_oauth(server.get()); +#endif // MODULE_OAUTH } int start_wormhole() diff --git a/src/protocol/CMakeLists.txt b/src/protocol/CMakeLists.txt index a097db8..fb15f75 100644 --- a/src/protocol/CMakeLists.txt +++ b/src/protocol/CMakeLists.txt @@ -9,3 +9,7 @@ endif() if (MODULE_HOST_META) add_subdirectory(host-meta) endif() + +if (MODULE_OAUTH) + add_subdirectory(oauth) +endif() diff --git a/src/protocol/oauth/CMakeLists.txt b/src/protocol/oauth/CMakeLists.txt new file mode 100644 index 0000000..90a4f5f --- /dev/null +++ b/src/protocol/oauth/CMakeLists.txt @@ -0,0 +1,4 @@ +add_library(wormhole_oauth_module + oauth.cpp) +include_directories(wormhole_oauth_module ${WORMHOLE_INCLUDE_DIRS}) +target_link_libraries(wormhole_oauth_module wormhole_lib) diff --git a/src/protocol/oauth/oauth.cpp b/src/protocol/oauth/oauth.cpp new file mode 100644 index 0000000..b1e8ac3 --- /dev/null +++ b/src/protocol/oauth/oauth.cpp @@ -0,0 +1,53 @@ +/* + * Wormhole - Federated social network + * Copyright (C) 2022 Nekobit + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + + +#include +#include +#include "oauth.h" +#include "instance/instance.h" +#include "http/mime.h" +#include "http/response.h" +#include "http/responsecode.h" +#include "http/httpserver.h" +#include "http/error_response.h" +#include "http/request.h" +#include "user.h" +#include "logger.h" +#include "jsonhelper.h" +#include "route_args.h" + +using namespace Protocol; + + +HTTP::Response Route::oauth_authorize(std::any& args, + const HTTP::Request& req, + const HTTP::RequestArgs_t& arg) +{ + using namespace std::string_literals; + + //DESTRUCT_WORMHOLE_ARGS(args); + + // Sorry :-) + return HTTP::Response{ "{}", HTTP::MIME::JSON }; +} + +void OAuth::init_oauth(HTTP::Server* server) +{ + server->add_route({{HTTP::Request::Type::GET, "/authorize"}, Route::oauth_authorize}); +} diff --git a/src/protocol/oauth/oauth.h b/src/protocol/oauth/oauth.h new file mode 100644 index 0000000..848d30b --- /dev/null +++ b/src/protocol/oauth/oauth.h @@ -0,0 +1,37 @@ +/* + * Wormhole - Federated social network + * Copyright (C) 2022 Nekobit + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include "http/httpserver.h" +#include "http/response.h" + +namespace Route +{ + HTTP::Response oauth_authorize(std::any& args, + const HTTP::Request& req, + const HTTP::RequestArgs_t& arg); +} + +namespace Protocol +{ + namespace OAuth + { + void init_oauth(HTTP::Server* server); + } +}