more changes
This commit is contained in:
@@ -20,6 +20,7 @@ set(HEADERS
|
|||||||
include/directory_manager.h
|
include/directory_manager.h
|
||||||
include/imageFile.h
|
include/imageFile.h
|
||||||
include/metadata_retriever.h
|
include/metadata_retriever.h
|
||||||
|
include/token_manager.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set (TAGLIB
|
set (TAGLIB
|
||||||
@@ -60,6 +61,9 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/cpr)
|
|||||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/taglib)
|
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/taglib)
|
||||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/oatpp)
|
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/oatpp)
|
||||||
|
|
||||||
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/appsettings.json ${CMAKE_BINARY_DIR}/bin/appsettings.json COPYONLY)
|
||||||
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/authcredentials.json ${CMAKE_BINARY_DIR}/bin/authcredentials.json COPYONLY)
|
||||||
|
|
||||||
add_executable(icarus ${SOURCES} ${HEADERS})
|
add_executable(icarus ${SOURCES} ${HEADERS})
|
||||||
target_include_directories(icarus PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/jwt-cpp/include)
|
target_include_directories(icarus PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/jwt-cpp/include)
|
||||||
target_link_libraries(icarus "-lstdc++fs" tag oatpp ${CONAN_LIBS} ${CPR_LIBRARIES})
|
target_link_libraries(icarus "-lstdc++fs" tag oatpp ${CONAN_LIBS} ${CPR_LIBRARIES})
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"Domain": "[domain].auth0.com",
|
||||||
|
"ApiIdentifier": "https://[identifier]/api",
|
||||||
|
"ClientId": "dfdfdfdf",
|
||||||
|
"ClientSecret": "dfdfdfdf"
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
#ifndef MODELS_H_
|
#ifndef MODELS_H_
|
||||||
#define MODELS_H_
|
#define MODELS_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
struct Song
|
struct Song
|
||||||
{
|
{
|
||||||
int Id;
|
int Id;
|
||||||
@@ -30,6 +32,24 @@ struct LoginRes
|
|||||||
int Expiration;
|
int Expiration;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct loginResult
|
||||||
|
{
|
||||||
|
int user_id;
|
||||||
|
std::string username;
|
||||||
|
std::string access_token;
|
||||||
|
std::string token_type;
|
||||||
|
std::string message;
|
||||||
|
int expiration;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct auth_credentials
|
||||||
|
{
|
||||||
|
std::string domain;
|
||||||
|
std::string api_identifier;
|
||||||
|
std::string client_id;
|
||||||
|
std::string client_secret;
|
||||||
|
};
|
||||||
|
|
||||||
struct TokenReq
|
struct TokenReq
|
||||||
{
|
{
|
||||||
char ClientId[1024];
|
char ClientId[1024];
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#ifndef TOKEN_MANAGER_H_
|
||||||
|
#define TOKEN_MANAGER_H_
|
||||||
|
|
||||||
|
#include "models.h"
|
||||||
|
|
||||||
|
class token_manager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
token_manager();
|
||||||
|
|
||||||
|
loginResult retrieve_token();
|
||||||
|
|
||||||
|
//LoginRes* retrieve_token(TokenReq *tok);
|
||||||
|
private:
|
||||||
|
auth_credentials parse_auth_credentials();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,18 +1,29 @@
|
|||||||
#ifndef LOGINCONTROLLER_H_
|
#ifndef LOGINCONTROLLER_H_
|
||||||
#define LOGINCONTROLLER_H_
|
#define LOGINCONTROLLER_H_
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "oatpp/core/macro/codegen.hpp"
|
#include "oatpp/core/macro/codegen.hpp"
|
||||||
#include "oatpp/core/macro/component.hpp"
|
#include "oatpp/core/macro/component.hpp"
|
||||||
#include "oatpp/web/server/api/ApiController.hpp"
|
#include "oatpp/web/server/api/ApiController.hpp"
|
||||||
|
|
||||||
#include "../dto/loginResultDto.hpp"
|
#include "../dto/loginResultDto.hpp"
|
||||||
|
#include "token_manager.h"
|
||||||
|
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
class loginController : public oatpp::web::server::api::ApiController
|
class loginController : public oatpp::web::server::api::ApiController
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
loginController(OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
|
loginController(std::string p, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
|
||||||
: oatpp::web::server::api::ApiController(objectMapper)
|
: oatpp::web::server::api::ApiController(objectMapper), exe_path(fs::canonical(p.c_str()).parent_path().string())
|
||||||
{ }
|
{
|
||||||
|
std::cout << "p is " << p << std::endl;
|
||||||
|
std::cout << "working path " << exe_path.string() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#include OATPP_CODEGEN_BEGIN(ApiController)
|
#include OATPP_CODEGEN_BEGIN(ApiController)
|
||||||
|
|
||||||
@@ -20,15 +31,19 @@ public:
|
|||||||
{
|
{
|
||||||
OATPP_LOGI("icarus", "logging in");
|
OATPP_LOGI("icarus", "logging in");
|
||||||
|
|
||||||
|
token_manager tok;
|
||||||
|
auto token = tok.retrieve_token();
|
||||||
|
|
||||||
auto logRes = loginResultDto::createShared();
|
auto logRes = loginResultDto::createShared();
|
||||||
logRes->access_token = "sdfsdfsdfsdert";
|
logRes->access_token = token.access_token.c_str();
|
||||||
logRes->token_type = "Special";
|
logRes->token_type = token.token_type.c_str();
|
||||||
|
|
||||||
return createDtoResponse(Status::CODE_200, logRes);
|
return createDtoResponse(Status::CODE_200, logRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include OATPP_CODEGEN_END(ApiController)
|
#include OATPP_CODEGEN_END(ApiController)
|
||||||
private:
|
private:
|
||||||
|
fs::path exe_path;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+10
-3
@@ -1,5 +1,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <filesystem>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "oatpp/network/server/Server.hpp"
|
#include "oatpp/network/server/Server.hpp"
|
||||||
#include "oatpp/network/server/SimpleTCPConnectionProvider.hpp"
|
#include "oatpp/network/server/SimpleTCPConnectionProvider.hpp"
|
||||||
@@ -9,7 +11,9 @@
|
|||||||
#include "controller/loginController.hpp"
|
#include "controller/loginController.hpp"
|
||||||
//#include "loginHandler.hpp"
|
//#include "loginHandler.hpp"
|
||||||
|
|
||||||
void run()
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
|
void run(const std::string& working_path)
|
||||||
{
|
{
|
||||||
appComponent component;
|
appComponent component;
|
||||||
|
|
||||||
@@ -17,7 +21,7 @@ void run()
|
|||||||
OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router);
|
OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router);
|
||||||
|
|
||||||
//router->route("GET", "/test", std::make_shared<loginHandler>());
|
//router->route("GET", "/test", std::make_shared<loginHandler>());
|
||||||
auto logController = std::make_shared<loginController>();
|
auto logController = std::make_shared<loginController>(working_path);
|
||||||
logController->addEndpointsToRouter(router);
|
logController->addEndpointsToRouter(router);
|
||||||
|
|
||||||
OATPP_COMPONENT(std::shared_ptr<oatpp::network::server::ConnectionHandler>, connectionHandler);
|
OATPP_COMPONENT(std::shared_ptr<oatpp::network::server::ConnectionHandler>, connectionHandler);
|
||||||
@@ -31,11 +35,14 @@ void run()
|
|||||||
server.run();
|
server.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
oatpp::base::Environment::init();
|
oatpp::base::Environment::init();
|
||||||
|
std::string working_path = argv[0];
|
||||||
|
//std::cout << fs::canonical(fs::path(working_path.c_str())).parent_path().string() << std::endl;
|
||||||
|
|
||||||
run();
|
run(working_path);
|
||||||
|
|
||||||
oatpp::base::Environment::destroy();
|
oatpp::base::Environment::destroy();
|
||||||
|
|
||||||
|
|||||||
+35
-4
@@ -1,18 +1,48 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <filesystem>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
#include <cpr/cpr.h>
|
#include <cpr/cpr.h>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
#include "models.h"
|
//#include "models.h"
|
||||||
|
#include "token_manager.h"
|
||||||
|
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
|
//extern "C"
|
||||||
|
//{
|
||||||
|
|
||||||
|
|
||||||
extern "C"
|
token_manager::token_manager()
|
||||||
{
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
loginResult token_manager::retrieve_token()
|
||||||
|
{
|
||||||
|
auto cred = parse_auth_credentials();
|
||||||
|
|
||||||
LoginRes* retrieve_token(TokenReq *tok)
|
loginResult lr;
|
||||||
|
lr.access_token = "dsfdsf";
|
||||||
|
lr.token_type = "demo";
|
||||||
|
|
||||||
|
return lr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auth_credentials token_manager::parse_auth_credentials()
|
||||||
|
{
|
||||||
|
auth_credentials auth;
|
||||||
|
//auto ss = working_path.string();
|
||||||
|
//auto path = fs::canonical(fs::path("."));
|
||||||
|
//std::cout << "canonical path " << path.string() << std::endl;
|
||||||
|
|
||||||
|
return auth;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
LoginRes* token_manager::retrieve_token(TokenReq *tok)
|
||||||
{
|
{
|
||||||
LoginRes *res = new LoginRes;
|
LoginRes *res = new LoginRes;
|
||||||
|
|
||||||
@@ -38,4 +68,5 @@ LoginRes* retrieve_token(TokenReq *tok)
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
*/
|
||||||
|
//}
|
||||||
|
|||||||
Reference in New Issue
Block a user