#pragma once #include #include #include #include #include #include namespace rublon::method { class WebsocketBasedAuth : public AuthenticationStep { public: const char * _name = ""; const bool _autopushPrompt = true; WebsocketBasedAuth(Session & session, const char * name, bool autopushPrompt = true) : AuthenticationStep(session), _name{name}, _autopushPrompt{autopushPrompt} {} /// TODO refactor this code template < typename Hander_t > tl::expected< AuthenticationStatus, Error > verify(const CoreHandlerInterface< Hander_t > & coreHandler, const Pam_t & pam) const { log(LogLevel::Info, "starting WS"); 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"); RublonEventData event = coreHandler.listen(); if(event.status == transactionConfirmed ){ log(LogLevel::Debug, " transaction confirmed jupi"); return AuthenticationStatus{AuthenticationStatus::Action::Confirmed, std::string{event.accessToken.value().c_str()}}; } log(LogLevel::Debug, " transaction denied"); return AuthenticationStatus{AuthenticationStatus::Action::Denied}; } }; } // namespace rublon::method