MCPcopy Create free account
hub / github.com/comaps/comaps / FindAuthenticityToken

Function FindAuthenticityToken

libs/editor/osm_auth.cpp:23–40  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21
22
23string FindAuthenticityToken(string const & action, string body)
24{
25 static boost::regex const kActionAndTokenRE(R"~(action="(.+?)".*?name="authenticity_token" value="(.+?)")~");
26
27 // Regex doesn't support multiline matches. Need to remove all line endings from the body.
28 std::erase_if(body, [](char c) { return c == '\n' || c == '\r'; });
29
30 auto const begin = boost::sregex_iterator{body.begin(), body.end(), kActionAndTokenRE};
31 auto const end = boost::sregex_iterator{};
32
33 for (auto it = begin; it != end; ++it)
34 {
35 auto const match = *it;
36 if (match.size() == 3 && match[1] == action)
37 return match[2];
38 }
39 MYTHROW(OsmOAuth::AuthenticityTokenNotFound, ("authenticity_token for action", action, "was not found in", body));
40}
41
42// Parse URL in format "{OSM_OAUTH2_REDIRECT_URI}?code=XXXX". Extract code value
43string FindOauthCode(string const & redirectUri)

Callers 3

FetchSessionIdMethod · 0.70
FetchRequestTokenMethod · 0.70
UNIT_TESTFunction · 0.50

Calls 4

erase_ifFunction · 0.85
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by 1

UNIT_TESTFunction · 0.40