-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/auth builder #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only things I think must change are the lack of escaping around the query params and JSON key/values, other than that it looks good.
src/api.cpp
Outdated
|
||
std::stringstream queryStrStream; | ||
for (const auto& pair : queryParams) { | ||
queryStrStream << pair.first << "=" << pair.second << "&"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential future footgun with unescaped query parameters
Also this seems like a candidate to be replaced with std::string queryString()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated this to make a call to queryString (which now does url encoding of the pair values)
return url; | ||
} | ||
|
||
std::string MarketplaceApi::getGatewayUrl( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there future logic that is planned which will make this function materially different from getAuthUrl?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potentially yes, as the calls to the gateway API have various standard parameters such as limits/offsets. My thought is to standardize this in the future for easier/more clear calls to the various API endpoints versus the calls done to the OAuth process
src/util.cpp
Outdated
{ | ||
std::stringstream queryStrStream; | ||
for (const auto& pair : params) { | ||
queryStrStream << "\"" << pair.first << "\": \"" << pair.second << "\","; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unescaped JSON keys/values too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed by doing a round trip with nlohmann::json
from std::map
--> json object
--> std::string
which escapes json values.
std::map<std::string, std::string> const& queryParams | ||
) | ||
{ | ||
std::string endpoint = segments.size() > 0 ? std::accumulate(std::next(segments.begin()), segments.end(), segments[0], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is technically not "bad" code, but I prefer when algorithms like this are spun out into a well named helper function; especially when it's a pattern used in multiple places for a relatively well understood high level operation like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've noted this, and will revisit.
… escaping for all json post bodies.
No description provided.