66 lines
2.3 KiB
C++
66 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include <rublon/json.hpp>
|
|
#include <rublon/pam.hpp>
|
|
|
|
#include <rublon/authentication_step_interface.hpp>
|
|
#include <rublon/configuration.hpp>
|
|
|
|
#include <rublon/method/method_factory.hpp>
|
|
|
|
namespace rublon{
|
|
class Verify{};
|
|
}
|
|
|
|
namespace rublon {
|
|
template < class MethodSelect_t = MethodSelect, typename Pam_t = LinuxPam >
|
|
class Init : public AuthenticationStep< Init< MethodSelect_t, Pam_t > > {
|
|
using base_t = AuthenticationStep< Init< MethodSelect_t, Pam_t > >;
|
|
|
|
const char * apiPath = "/api/transaction/init";
|
|
|
|
protected:
|
|
Pam_t & _pamInfo;
|
|
|
|
public:
|
|
const char * name = "Initialization";
|
|
|
|
Init(Pam_t & pamHandler, const rublon::Configuration & config)
|
|
: base_t(config.parameters.systemToken, ""), _pamInfo{pamHandler} {}
|
|
|
|
/// TODO add core handler interface
|
|
template < typename Hander_t >
|
|
tl::expected< MethodSelect_t, PamAction > handle(const CoreHandlerInterface< Hander_t > & coreHandler) const {
|
|
char _buffer[1024];
|
|
std::pmr::monotonic_buffer_resource mr{_buffer, 1024};
|
|
|
|
RapidJSONPMRAlloc alloc{&mr};
|
|
Document body{rapidjson::kObjectType, &alloc};
|
|
|
|
body.AddMember("systemToken", Value{this->_systemToken.c_str(), alloc}, alloc);
|
|
body.AddMember("username", Value{this->_pamInfo.username().get(), alloc}, alloc);
|
|
body.AddMember("userEmail", "bwi@rublon.com", alloc); /// TODO proper username
|
|
|
|
Value params{rapidjson::kObjectType};
|
|
params.AddMember("userIP", Value{_pamInfo.ip().get(), alloc}, alloc);
|
|
params.AddMember("appVer", "v.1.6", alloc); /// TODO add version to cmake
|
|
params.AddMember("os", "Ubuntu 23.04", alloc); /// TODO add version to cmake
|
|
|
|
body.AddMember("params", std::move(params), alloc);
|
|
|
|
auto coreResponse = coreHandler.request(apiPath, body);
|
|
|
|
if(coreResponse.has_value()) {
|
|
log(LogLevel::Info, "[TMP] has response, processing", __PRETTY_FUNCTION__);
|
|
const auto & rublonResponse = coreResponse.value()["result"];
|
|
std::string tid = rublonResponse["tid"].GetString();
|
|
return MethodSelect_t{this->_systemToken, tid, rublonResponse["methods"]};
|
|
} else {
|
|
return tl::unexpected{this->coreErrorHandler(coreResponse)};
|
|
}
|
|
|
|
return tl::unexpected{PamAction::decline};
|
|
}
|
|
};
|
|
} // namespace rublon
|