2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
42#include "express/middleware/BasicAuthentication.h"
44#ifndef DOXYGEN_SHOULD_SKIP_THIS
46#include "utils/base64.h"
47#include "web/http/http_utils.h"
54namespace express::middleware {
57 std::string userNamePassword = userName +
":" + password;
58 const std::string credentials =
61 use([realm, credentials]
MIDDLEWARE(req, res, next) {
64 if (authCredentials == credentials) {
67 if (authCredentials.empty()) {
68 res->
set("WWW-Authenticate", "Basic realm=\"" + realm +
"\"");
83 return *basicAuthentication;
#define MIDDLEWARE(req, res, next)
void operator()(const std::string &how="") const
const std::string & get(const std::string &key, int i=0) const
Response & set(const std::string &field, const std::string &value, bool overwrite=true)
void sendStatus(int state)
friend class BasicAuthentication & BasicAuthentication(const std::string &userName, const std::string &password, const std::string &realm)
BasicAuthentication(const std::string &userName, const std::string &password, const std::string &realm)
static class BasicAuthentication & instance(const std::string &userName, const std::string &password, const std::string &realm)
std::string base64_encode(const unsigned char *bytes_to_encode, std::size_t length)
std::pair< std::string, std::string > str_split(const std::string &base, char c_middle)