rublon-ssh/PAM/ssh/include/rublon/method/websocket_based_auth.hpp
2024-06-17 12:50:06 +02:00

36 lines
1.2 KiB
C++
Executable File

#pragma once
#include <tl/expected.hpp>
#include <rublon/authentication_step_interface.hpp>
#include <rublon/bits.hpp>
#include <rublon/configuration.hpp>
#include <rublon/pam_action.hpp>
#include <rublon/websockets.hpp>
namespace rublon::method {
class WebsocketBasedAuth : public AuthenticationStep {
public:
const char * _name = "";
const bool _autopushPrompt = true;
WebsocketBasedAuth(std::string systemToken, std::string tid, const char * name, bool autopushPrompt = true)
: AuthenticationStep(std::move(systemToken), std::move(tid)), _name{name}, _autopushPrompt{autopushPrompt} {}
template < typename Hander_t >
tl::expected< AuthenticationStatus, Error > verify(const CoreHandlerInterface< Hander_t > & coreHandler, const Pam_t & pam) const {
log(LogLevel::Info, "starting WS");
auto listener = coreHandler.listen();
if(not _autopushPrompt)
pam.print("Autopush");
else
pam.scan([](const auto /*ignored userinput*/) { return ""; },
"Rublon authentication initiated. Complete the authentication and press Enter to proceed");
return listener->waitForEvent();
}
};
} // namespace rublon::method