|
|
@@ -11777,7 +11777,7 @@ inline bool parse_www_authenticate(const Response &res,
|
|
|
// trimmed before its boundaries are inspected.
|
|
|
auto key_part = trim_copy(
|
|
|
eq_pos == std::string::npos ? segment : segment.substr(0, eq_pos));
|
|
|
- auto space_pos = key_part.find_last_of(" \t");
|
|
|
+ auto space_pos = key_part.find_first_of(" \t");
|
|
|
if (space_pos != std::string::npos || eq_pos == std::string::npos) {
|
|
|
// "<scheme>[ <key>]" starts a new challenge.
|
|
|
take_challenge_if_answerable();
|
|
|
@@ -11789,7 +11789,7 @@ inline bool parse_www_authenticate(const Response &res,
|
|
|
// Bare scheme (or a token68), no auth-param on this segment.
|
|
|
return;
|
|
|
}
|
|
|
- key_part = key_part.substr(space_pos + 1);
|
|
|
+ key_part = trim_copy(key_part.substr(space_pos + 1));
|
|
|
}
|
|
|
|
|
|
if (!in_digest_challenge) { return; }
|
|
|
@@ -12330,15 +12330,16 @@ inline bool set_socket_opt(socket_t sock, int level, int optname, int optval) {
|
|
|
}
|
|
|
|
|
|
inline std::string get_bearer_token_auth(const Request &req) {
|
|
|
- // The auth scheme is case-insensitive (RFC 9110 11.1), and a value shorter
|
|
|
- // than the prefix carries no token.
|
|
|
+ // The auth scheme is case-insensitive (RFC 9110 11.1) and followed by 1*SP,
|
|
|
+ // and a value shorter than the prefix carries no token.
|
|
|
constexpr const char bearer_prefix[] = "Bearer ";
|
|
|
constexpr auto bearer_prefix_len = detail::str_len(bearer_prefix);
|
|
|
auto value = req.get_header_value("Authorization");
|
|
|
if (value.size() >= bearer_prefix_len &&
|
|
|
detail::case_ignore::equal(value.substr(0, bearer_prefix_len),
|
|
|
bearer_prefix)) {
|
|
|
- return value.substr(bearer_prefix_len);
|
|
|
+ auto pos = value.find_first_not_of(' ', bearer_prefix_len);
|
|
|
+ if (pos != std::string::npos) { return value.substr(pos); }
|
|
|
}
|
|
|
return "";
|
|
|
}
|