6#ifndef MANTISBASE_AUTH_METHODS_H
7#define MANTISBASE_AUTH_METHODS_H
9#include <nlohmann/json.hpp>
27 [[nodiscard]] nlohmann::json
toJSON()
const {
39 if (!auth.is_object())
41 auto take = [&](
const char *key,
bool &dest) {
42 if (auth.contains(key) && auth[key].is_boolean())
43 dest = auth[key].get<
bool>();
46 take(
"otp", methods.
otp);
47 take(
"oauth", methods.
oauth);
58 if (!auth.is_object())
59 throw MbException(400,
"Expected `auth` to be an object.");
60 for (
const auto &[key, value]: auth.items()) {
61 if (key !=
"password" && key !=
"otp" && key !=
"oauth" && key !=
"requireEmailVerification")
62 throw MbException(400,
"Unknown auth setting `" + key +
"`.");
63 if (!value.is_boolean())
64 throw MbException(400,
"Expected `auth." + key +
"` to be a boolean.");
65 if (key ==
"password")
67 else if (key ==
"otp")
68 otp = value.get<
bool>();
69 else if (key ==
"oauth")
70 oauth = value.get<
bool>();
Application exception carrying an HTTP status code and messages.
Definition exceptions.h:23
Custom exception class for MantisBase errors.
DLL/shared-library symbol visibility macros for MantisBase.
#define MANTISBASE_API
Definition export.h:31
Definition auth_methods.h:21
nlohmann::json toJSON() const
Definition auth_methods.h:27
bool otp
Definition auth_methods.h:23
bool password
Definition auth_methods.h:22
static MbAuthMethods fromJSON(const nlohmann::json &auth)
Definition auth_methods.h:37
bool oauth
Definition auth_methods.h:24
void mergeStrict(const nlohmann::json &auth)
Definition auth_methods.h:57
bool requireEmailVerification
Definition auth_methods.h:25