OAuth basis

FossilOrigin-Name: 87ce301e426d719f43838665c7ac537cd5bdd00082a353546c66bd946b5b7800
This commit is contained in:
nekobit 2022-10-21 17:17:34 +00:00
parent ab163ce4dd
commit 8f2184983b
6 changed files with 115 additions and 6 deletions

View file

@ -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}

View file

@ -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<HTTP::Server>& 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()

View file

@ -9,3 +9,7 @@ endif()
if (MODULE_HOST_META)
add_subdirectory(host-meta)
endif()
if (MODULE_OAUTH)
add_subdirectory(oauth)
endif()

View file

@ -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)

View file

@ -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 <https://www.gnu.org/licenses/>.
*/
#include <stdexcept>
#include <utility>
#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});
}

View file

@ -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 <https://www.gnu.org/licenses/>.
*/
#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);
}
}