46 lines
1.6 KiB
C++
46 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#include <tl/expected.hpp>
|
|
|
|
#include <rublon/authentication_step_interface.hpp>
|
|
#include <rublon/pam.hpp>
|
|
#include <rublon/pam_action.hpp>
|
|
|
|
namespace rublon::method {
|
|
|
|
class OTP : public AuthenticationStep< OTP > {
|
|
using base_t = AuthenticationStep< OTP >;
|
|
const char * uri = "/api/transaction/confirmCode";
|
|
|
|
public:
|
|
const char * name = "TOTP";
|
|
|
|
OTP(std::string systemToken, std::string tid) : base_t(std::move(systemToken), std::move(tid)) {}
|
|
|
|
template < typename Hander_t, typename PamInfo_t = LinuxPam >
|
|
tl::expected< AuthenticationStatus, Error > handle(const CoreHandlerInterface< Hander_t > & coreHandler, const PamInfo_t & pam) const {
|
|
RapidJSONPMRStackAlloc< 1024 > alloc{};
|
|
Document body{rapidjson::kObjectType, &alloc};
|
|
|
|
this->addSystemToken(body, alloc);
|
|
this->addTid(body, alloc);
|
|
|
|
const auto passcode =
|
|
pam.scan([](const char * userInput) { return std::string{userInput}; }, "Mobile TOTP from Rublon Authenticator:");
|
|
|
|
body.AddMember("vericode", Value{passcode.value().c_str(), alloc}, alloc); /// TODO proper username
|
|
|
|
auto coreResponse = coreHandler.request(uri, body);
|
|
|
|
if(coreResponse.has_value()) {
|
|
// const auto & rublonResponse = coreResponse.value()["result"];
|
|
// {"status":"OK","result":true}
|
|
return AuthenticationStatus{AuthenticationStatus::Action::Confirmed};
|
|
} else {
|
|
return tl::unexpected{this->coreErrorHandler(coreResponse)};
|
|
}
|
|
}
|
|
};
|
|
|
|
} // namespace rublon::method
|