58 lines
2.1 KiB
C++
58 lines
2.1 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
|
|
|
|
namespace rublon {
|
|
template < class MethodSelect_t = MethodSelect >
|
|
class Init : public AuthenticationStep< Init< MethodSelect_t > > {
|
|
using base_t = AuthenticationStep< Init< MethodSelect_t > >;
|
|
|
|
const char * apiPath = "/api/transaction/init";
|
|
|
|
public:
|
|
const char * name = "Initialization";
|
|
|
|
Init(const rublon::Configuration & config) : base_t(config.parameters.systemToken, "") {}
|
|
|
|
/// TODO add core handler interface
|
|
template < typename Hander_t, typename PamInfo_t = LinuxPam >
|
|
tl::expected< MethodSelect_t, Error > handle(const CoreHandlerInterface< Hander_t > & coreHandler, const PamInfo_t & pam) const {
|
|
RapidJSONPMRStackAlloc< 1024 > alloc{};
|
|
Document body{rapidjson::kObjectType, &alloc};
|
|
|
|
this->addSystemToken(body, alloc);
|
|
|
|
body.AddMember("username", Value{pam.username().get(), alloc}, alloc);
|
|
body.AddMember("userEmail", "bwi@rublon.com", alloc); /// TODO proper username
|
|
|
|
Value params{rapidjson::kObjectType};
|
|
params.AddMember("userIP", Value{pam.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)};
|
|
}
|
|
}
|
|
};
|
|
} // namespace rublon
|