MCPcopy Create free account
hub / github.com/apache/nifi-minifi-cpp / get_token

Function get_token

libminifi/src/utils/HTTPClient.cpp:26–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24namespace utils {
25
26std::string get_token(utils::BaseHTTPClient *client, std::string username, std::string password) {
27 if (nullptr == client) {
28 return "";
29 }
30 std::string token;
31
32 client->setContentType("application/x-www-form-urlencoded");
33
34 client->set_request_method("POST");
35
36 std::string payload = "username=" + username + "&" + "password=" + password;
37
38 client->setPostFields(client->escape(payload));
39
40 client->submit();
41
42 if (client->submit() && client->getResponseCode() == 200) {
43 const std::string &response_body = std::string(client->getResponseBody().data(), client->getResponseBody().size());
44 if (!response_body.empty()) {
45 token = "Bearer " + response_body;
46 }
47 }
48 return token;
49}
50
51void parse_url(const std::string *url, std::string *host, int *port, std::string *protocol) {
52 static std::string http("http://");

Callers 1

Calls 8

setContentTypeMethod · 0.80
set_request_methodMethod · 0.80
setPostFieldsMethod · 0.80
escapeMethod · 0.80
submitMethod · 0.80
getResponseCodeMethod · 0.80
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected