Skip to content

Conversation

@walves-cit
Copy link
Contributor

This plugin is a HMAC cookie authorization showcase.

Technically, this is performed by ensuring that the request has a valid HMAC cookie.

This examples contains only a C++ version.

@walves-cit walves-cit marked this pull request as ready for review September 9, 2024 19:37
@walves-cit walves-cit requested a review from a team as a code owner September 9, 2024 19:37
@snippet-bot
Copy link

snippet-bot bot commented Sep 9, 2024

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

const auto path = getRequestHeader(":path")->toString();
if (computeHmacSignature(path) != token.value()) {
const std::optional<std::pair<std::string, std::string>> payload_and_hash =
parseAuthorizationCookie(token.value());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: can dereference using *token instead of token.value(), since has_value() has been checked earlier. *token is shorter and doesn't have behavior that depends on build mode (i.e. whether or not to throw an exception)

FilterHeadersStatus onRequestHeaders(uint32_t headers,
bool end_of_stream) override {
const auto token = getTokenFromCookie();
const std::optional<std::string> ip = getClientIp();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice structuring of this method! The factoring of checks/parsing into helper methods make it very clear.

@mpwarres mpwarres merged commit 7f02bfc into GoogleCloudPlatform:main Mar 5, 2025
7 checks passed
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.

3 participants