Skip to content

Conversation

FiniteSingularity
Copy link
Collaborator

No description provided.

Copy link
Collaborator

@Elgato-AStory Elgato-AStory left a 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 << "&";
Copy link
Collaborator

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()

Copy link
Collaborator Author

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(
Copy link
Collaborator

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?

Copy link
Collaborator Author

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 << "\",";
Copy link
Collaborator

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

Copy link
Collaborator Author

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],
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

@FiniteSingularity FiniteSingularity merged commit b54b190 into main Feb 28, 2025
3 checks passed
@FiniteSingularity FiniteSingularity deleted the feature/auth-builder branch February 28, 2025 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants