cross build
This commit is contained in:
1 parent
760c3f8062
commit
a0de61a6c0
17 files changed
+102
-79
No files matched your search
+3
-2
@@ -1,9 +1,8 @@
|
||||
cmake_minimum_required (VERSION 2.6)
|
||||
project(auth_service)
|
||||
set(CMAKE_CXX_COMPILER /home/tola/Documents/linux/orangepipc/buildroot-2024.08.2/output/host/bin/arm-buildroot-linux-uclibcgnueabihf-g++)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
include_directories(./src/libs/)
|
||||
include_directories(./src/libs/ ./src)
|
||||
|
||||
add_executable(
|
||||
auth_service
|
||||
@@ -21,6 +20,8 @@ add_executable(
|
||||
src/users/change_user.cpp
|
||||
|
||||
src/security/cors.cpp
|
||||
|
||||
src/AuthService/AuthService.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(auth_service ssl crypto)
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
#include <AuthService/AuthService.hpp>
|
||||
#include <auth/auth.hpp>
|
||||
#include <users/users.hpp>
|
||||
#include <security/cors.hpp>
|
||||
#include <colors.h>
|
||||
|
||||
AuthService::AuthService()
|
||||
{
|
||||
this->srv.Post("/api/token", auth);
|
||||
this->srv.Post("/api/users/user", get_user);
|
||||
this->srv.Post("/api/users/all", get_all_users);
|
||||
this->srv.Post("/api/users/add", add_user);
|
||||
this->srv.Post("/api/users/user/password/change", change_password);
|
||||
this->srv.Post("/api/users/del", delete_user);
|
||||
this->srv.Post("/api/access", user_access);
|
||||
this->srv.Post("/api/users/user/change", change_user);
|
||||
|
||||
this->srv.Options("/(.*)", set_cors_headers);
|
||||
|
||||
this->srv.set_mount_point("/auth/admin", "../src/web");
|
||||
this->srv.set_mount_point("/auth/js", "../src/web/js");
|
||||
this->srv.set_mount_point("/auth/css", "../src/web/css");
|
||||
}
|
||||
|
||||
AuthService::~AuthService() = default;
|
||||
|
||||
int AuthService::serve(const std::string &ip, int port, int socket_flags)
|
||||
{
|
||||
std::cout << GREEN << "Starting" << RESET << " server on [ " << YELLOW
|
||||
<< ip << RESET << ":" << CYAN << port << RESET << " ]" << std::endl;
|
||||
this->srv.listen(ip, port, socket_flags);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <httplib.h>
|
||||
|
||||
#define CORS_ENABLE
|
||||
|
||||
class AuthService
|
||||
{
|
||||
private:
|
||||
httplib::Server srv;
|
||||
public:
|
||||
AuthService();
|
||||
~AuthService();
|
||||
int serve(const std::string &ip, int port, int socket_flags = 0);
|
||||
};
|
||||
+5
-4
@@ -1,6 +1,7 @@
|
||||
#include "auth.hpp"
|
||||
#include "../colors.h"
|
||||
#include "../includes.hpp"
|
||||
#include <auth/auth.hpp>
|
||||
#include <json.hpp>
|
||||
#include <colors.h>
|
||||
#include <includes.hpp>
|
||||
#include <jwt.hpp>
|
||||
#include <syslog.h>
|
||||
|
||||
@@ -54,7 +55,7 @@ void auth(const httplib::Request &request, httplib::Response &response) {
|
||||
{"userId", userid}
|
||||
};
|
||||
|
||||
std::string token = JWT::createJWT(headers.dump(), payload.dump(), JWT_DEFAULT_SECRET);
|
||||
std::string token = JWT::createJWT(headers.dump(), payload.dump(), JWT_SECRET_KEY);
|
||||
|
||||
std::stringstream response_json;
|
||||
response_json << R"({"token":")" << token.c_str() << "\"}";
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <httplib.h>
|
||||
#include <json.hpp>
|
||||
|
||||
// function for authorization users
|
||||
void auth(const httplib::Request &request, httplib::Response &response);
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#include "auth.hpp"
|
||||
#include <auth/auth.hpp>
|
||||
#include <json.hpp>
|
||||
#include <includes.hpp>
|
||||
#include <jwt.hpp>
|
||||
#include "../includes.hpp"
|
||||
#include <syslog.h>
|
||||
|
||||
// function for verify tokens
|
||||
bool verify_auth(const std::string &token) {
|
||||
try {
|
||||
return JWT::verifyJWT(token, JWT_DEFAULT_SECRET);
|
||||
return JWT::verifyJWT(token, JWT_SECRET_KEY);
|
||||
} catch (const std::system_error &e) {
|
||||
std::cout << "Verification error: " << e.what() << std::endl;
|
||||
syslog(LOG_ERR, "token verification error");
|
||||
|
||||
+3
-33
@@ -1,36 +1,6 @@
|
||||
#include <iostream>
|
||||
#include <httplib.h>
|
||||
#include <json.hpp>
|
||||
#include "auth/auth.hpp"
|
||||
#include "users/users.hpp"
|
||||
#include "colors.h"
|
||||
#include <syslog.h>
|
||||
|
||||
#define CORS_ENABLE
|
||||
|
||||
#include "security/cors.hpp"
|
||||
#include <AuthService/AuthService.hpp>
|
||||
|
||||
int main() {
|
||||
httplib::Server srv;
|
||||
|
||||
srv.Post("/api/token", auth);
|
||||
srv.Post("/api/users/user", get_user);
|
||||
srv.Post("/api/users/all", get_all_users);
|
||||
srv.Post("/api/users/add", add_user);
|
||||
srv.Post("/api/users/user/password/change", change_password);
|
||||
srv.Post("/api/users/del", delete_user);
|
||||
srv.Post("/api/access", user_access);
|
||||
srv.Post("/api/users/user/change", change_user);
|
||||
|
||||
srv.Options("/(.*)", set_cors_headers);
|
||||
|
||||
srv.set_mount_point("/auth/admin", "../src/web");
|
||||
srv.set_mount_point("/auth/js", "../src/web/js");
|
||||
srv.set_mount_point("/auth/css", "../src/web/css");
|
||||
|
||||
std::cout << GREEN << "Starting" << RESET << " server on [ " << YELLOW
|
||||
<< "0.0.0.0" << RESET << ":" << CYAN << "43243" << RESET << " ]" << std::endl;
|
||||
syslog(LOG_INFO, "Authorization service started");
|
||||
srv.listen("0.0.0.0", 43243);
|
||||
return 0;
|
||||
AuthService auth_service;
|
||||
return auth_service.serve("127.0.0.1", 43243);
|
||||
}
|
||||
File renamed without changes.
@@ -1,5 +1,5 @@
|
||||
#include "cors.hpp"
|
||||
#include "../colors.h"
|
||||
#include <security/cors.hpp>
|
||||
#include <colors.h>
|
||||
|
||||
void set_cors_headers(const httplib::Request &request, httplib::Response &response) {
|
||||
std::cout << GREEN << request.path << " " << std::endl;
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#include "users.hpp"
|
||||
#include "../colors.h"
|
||||
#include "../includes.hpp"
|
||||
#include "../auth/auth.hpp"
|
||||
#include <users/users.hpp>
|
||||
#include <colors.h>
|
||||
#include <includes.hpp>
|
||||
#include <auth/auth.hpp>
|
||||
#include <syslog.h>
|
||||
#include <json.hpp>
|
||||
|
||||
// function for access or reject authorization
|
||||
void user_access(const httplib::Request &request, httplib::Response &response) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "users.hpp"
|
||||
#include "../colors.h"
|
||||
#include "../includes.hpp"
|
||||
#include "../auth/auth.hpp"
|
||||
#include <users/users.hpp>
|
||||
#include <colors.h>
|
||||
#include <includes.hpp>
|
||||
#include <auth/auth.hpp>
|
||||
#include <jwt.hpp>
|
||||
#include <syslog.h>
|
||||
|
||||
@@ -53,7 +53,7 @@ void add_user(const httplib::Request &request, httplib::Response &response) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string userid = JWT::get_payload(json_body["token"], JWT_DEFAULT_SECRET)["userId"];
|
||||
std::string userid = JWT::get_payload(json_body["token"], JWT_SECRET_KEY)["userId"];
|
||||
if (userid.empty()) {
|
||||
response.set_content(STRING403, JSON_TYPE);
|
||||
syslog(LOG_ERR, "access reject in add user request");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "users.hpp"
|
||||
#include "../colors.h"
|
||||
#include "../includes.hpp"
|
||||
#include "../auth/auth.hpp"
|
||||
#include <users/users.hpp>
|
||||
#include <colors.h>
|
||||
#include <includes.hpp>
|
||||
#include <auth/auth.hpp>
|
||||
#include <jwt.hpp>
|
||||
#include <syslog.h>
|
||||
|
||||
@@ -51,7 +51,7 @@ void change_password(const httplib::Request &request, httplib::Response &respons
|
||||
|
||||
if (json_body["userid"] == nullptr) { old_password = json_body["old_password"]; }
|
||||
|
||||
std::string userid = JWT::get_payload(json_body["token"], JWT_DEFAULT_SECRET)["userId"];
|
||||
std::string userid = JWT::get_payload(json_body["token"], JWT_SECRET_KEY)["userId"];
|
||||
if (userid.empty()) {
|
||||
response.set_content(STRING403, JSON_TYPE);
|
||||
syslog(LOG_ERR, "access reject in change password request");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "users.hpp"
|
||||
#include "../colors.h"
|
||||
#include "../includes.hpp"
|
||||
#include "../auth/auth.hpp"
|
||||
#include <users/users.hpp>
|
||||
#include <colors.h>
|
||||
#include <includes.hpp>
|
||||
#include <auth/auth.hpp>
|
||||
#include <jwt.hpp>
|
||||
#include <syslog.h>
|
||||
|
||||
@@ -39,7 +39,7 @@ void change_user(const httplib::Request &request, httplib::Response &response) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string userid = JWT::get_payload(json_body["token"], JWT_DEFAULT_SECRET)["userId"];
|
||||
std::string userid = JWT::get_payload(json_body["token"], JWT_SECRET_KEY)["userId"];
|
||||
if (userid.empty()) {
|
||||
response.set_content(STRING403, JSON_TYPE);
|
||||
syslog(LOG_ERR, "access reject in change user request");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "users.hpp"
|
||||
#include "../colors.h"
|
||||
#include "../includes.hpp"
|
||||
#include "../auth/auth.hpp"
|
||||
#include <users/users.hpp>
|
||||
#include <colors.h>
|
||||
#include <includes.hpp>
|
||||
#include <auth/auth.hpp>
|
||||
#include <jwt.hpp>
|
||||
#include <syslog.h>
|
||||
|
||||
@@ -31,7 +31,7 @@ void delete_user(const httplib::Request &request, httplib::Response &response) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string userid = JWT::get_payload(json_body["token"], JWT_DEFAULT_SECRET)["userId"];
|
||||
std::string userid = JWT::get_payload(json_body["token"], JWT_SECRET_KEY)["userId"];
|
||||
if (userid.empty()) {
|
||||
response.set_content(STRING403, JSON_TYPE);
|
||||
syslog(LOG_ERR, "access reject in delete user request");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "users.hpp"
|
||||
#include "../colors.h"
|
||||
#include "../includes.hpp"
|
||||
#include "../auth/auth.hpp"
|
||||
#include <users/users.hpp>
|
||||
#include <colors.h>
|
||||
#include <includes.hpp>
|
||||
#include <auth/auth.hpp>
|
||||
#include <jwt.hpp>
|
||||
#include <syslog.h>
|
||||
|
||||
@@ -26,7 +26,7 @@ void get_all_users(const httplib::Request &request, httplib::Response &response)
|
||||
syslog(LOG_ERR, "access reject in get all user request");
|
||||
return;
|
||||
}
|
||||
std::string userid = JWT::get_payload(json_body["token"], JWT_DEFAULT_SECRET)["userId"];
|
||||
std::string userid = JWT::get_payload(json_body["token"], JWT_SECRET_KEY)["userId"];
|
||||
if (userid.empty()) {
|
||||
response.set_content(STRING403, JSON_TYPE);
|
||||
syslog(LOG_ERR, "access reject in get all user request");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "users.hpp"
|
||||
#include "../colors.h"
|
||||
#include "../includes.hpp"
|
||||
#include "../auth/auth.hpp"
|
||||
#include <users/users.hpp>
|
||||
#include <colors.h>
|
||||
#include <includes.hpp>
|
||||
#include <auth/auth.hpp>
|
||||
#include <jwt.hpp>
|
||||
#include <syslog.h>
|
||||
|
||||
@@ -26,7 +26,7 @@ void get_user(const httplib::Request &request, httplib::Response &response) {
|
||||
syslog(LOG_ERR, "access reject in get user request");
|
||||
return;
|
||||
}
|
||||
std::string userid = JWT::get_payload(json_body["token"], JWT_DEFAULT_SECRET)["userId"];
|
||||
std::string userid = JWT::get_payload(json_body["token"], JWT_SECRET_KEY)["userId"];
|
||||
if (userid.empty()) {
|
||||
response.set_content(STRING403, JSON_TYPE);
|
||||
syslog(LOG_ERR, "access reject in get user request");
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
set(CMAKE_CXX_COMPILER /home/tola/Documents/linux/orangepipc/buildroot-2024.08.2/output/host/bin/arm-buildroot-linux-uclibcgnueabihf-g++)
|
||||
Reference in new issue
Block a user