8 #include <oatpp/web/server/api/ApiController.hpp>
9 #include <oatpp/parser/json/mapping/ObjectMapper.hpp>
10 #include <oatpp/core/macro/codegen.hpp>
11 #include <oatpp/core/macro/component.hpp>
13 #include OATPP_CODEGEN_BEGIN(ApiController)
44 : oatpp::web::server::api::ApiController(objectMapper)
50 info->summary =
"Log in and obtain a session key";
52 "Accepts a JSON body with 'username' and optional 'password' fields. "
53 "If the account has no password set, the password field is ignored. "
54 "Returns a session key that must be sent as 'Authorization: Bearer <sessionKey>' "
55 "on all subsequent API requests.";
57 info->addConsumes<oatpp::String>(
"application/json");
58 info->addResponse<oatpp::String>(Status::CODE_200,
"application/json");
59 info->addResponse<oatpp::String>(Status::CODE_400,
"application/json");
60 info->addResponse<oatpp::String>(Status::CODE_401,
"application/json");
62 ENDPOINT(
"POST",
"/auth/login", login, REQUEST(std::shared_ptr<IncomingRequest>, request))
69 info->summary =
"Log out and invalidate the current session key";
71 "Reads the Bearer token from the Authorization header and removes it from the "
72 "active session table. Always returns 200 regardless of whether the key "
73 "existed, so clients can safely call this even if already logged out.";
75 info->addResponse<oatpp::String>(Status::CODE_200,
"application/json");
77 ENDPOINT(
"POST",
"/auth/logout", logout, REQUEST(std::shared_ptr<IncomingRequest>, request))
83 std::shared_ptr<OutgoingResponse>
handleLogin(
const std::shared_ptr<IncomingRequest>& req);
85 std::shared_ptr<OutgoingResponse>
handleLogout(
const std::shared_ptr<IncomingRequest>& req);
88 #include OATPP_CODEGEN_END(ApiController)
std::shared_ptr< OutgoingResponse > handleLogin(const std::shared_ptr< IncomingRequest > &req)
std::shared_ptr< OutgoingResponse > handleLogout(const std::shared_ptr< IncomingRequest > &req)
DtAuthController(const std::shared_ptr< ObjectMapper > &objectMapper)
Definition: authController.h:43
ENDPOINT_INFO(login)
Definition: authController.h:48
DtAuthController — REST endpoints for user authentication.
Definition: authController.h:40
ENDPOINT_INFO(logout)
Definition: authController.h:67