37 std::string userNamePassword = userName +
":" + password;
38 const std::string credentials =
39 base64::base64_encode(
reinterpret_cast<
unsigned char*>(userNamePassword.data()), userNamePassword.length());
41 use([realm, credentials]
MIDDLEWARE(req, res, next) {
42 const std::string authCredentials = httputils::str_split(req->get(
"Authorization"),
' ').second;
44 if (authCredentials == credentials) {
47 if (authCredentials.empty()) {
48 res->set(
"WWW-Authenticate",
"Basic realm=\"" + realm +
"\"");
56 BasicAuthentication::instance(
const std::string& userName,
const std::string& password,
const std::string& realm) {
58 static std::list<std::shared_ptr<
class BasicAuthentication>> basicAuthentications;
60 BasicAuthentication* basicAuthentication =
new BasicAuthentication(userName, password, realm);
61 basicAuthentications.push_back(std::shared_ptr<BasicAuthentication>(basicAuthentication));
63 return *basicAuthentication;