Skip to content
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

feat(recaptcha): add mfa sample #8665

Draft
wants to merge 41 commits into
base: main
Choose a base branch
from
Draft

feat(recaptcha): add mfa sample #8665

wants to merge 41 commits into from

Conversation

Sita04
Copy link
Contributor

@Sita04 Sita04 commented Sep 21, 2023

Add reCAPTCHA Enterprise MFA sample

@Sita04 Sita04 requested review from yoshi-approver and a team as code owners September 21, 2023 19:29
@snippet-bot
Copy link

snippet-bot bot commented Sep 21, 2023

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

@product-auto-label product-auto-label bot added samples Issues that are directly related to samples. api: recaptchaenterprise Issues related to the reCAPTCHA Enterprise API. labels Sep 21, 2023
@Sita04 Sita04 marked this pull request as draft September 26, 2023 17:19
Copy link
Contributor

@minherz minherz left a comment

Choose a reason for hiding this comment

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

The tag recaptcha_enterprise_mfa_assessment is not used in the documentation.
I would challenge the need for this code sample at this point or to reference a relevant bug that justifies the change.

Given the volume of nit comments, can you please go through them and see if there is anything relevant before we LGTM this PR?

recaptcha_enterprise/snippets/pom.xml Outdated Show resolved Hide resolved
recaptcha_enterprise/snippets/pom.xml Outdated Show resolved Hide resolved
final String HMAC_KEY = "SOME_INTERNAL_UNSHARED_KEY";
final String hmacKey = "SOME_INTERNAL_UNSHARED_KEY";
Copy link
Contributor

Choose a reason for hiding this comment

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

It is a constant. The original naming was correct. Please, rollback.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed about the naming convention. But having a static string format within main() throws lint as its not the norm.

@@ -45,7 +45,7 @@ public static void searchRelatedAccountGroupMemberships(

SearchRelatedAccountGroupMembershipsRequest request =
SearchRelatedAccountGroupMembershipsRequest.newBuilder()
.setProject(projectId)
.setProject("projects/" + projectId)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: is it necessary? how did it work before this change?

Copy link
Contributor Author

@Sita04 Sita04 Oct 18, 2023

Choose a reason for hiding this comment

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

Yes, This was a recent API change from the product!

// Creates an assessment to obtain Multi-Factor Authentication result.
// If the result is unspecified, sends the request token to the caller to initiate MFA challenge.
// See, https://cloud.google.com/recaptcha-enterprise/docs/integrate-account-verification#understanding_the_configuration_process_of_mfa
public static void createMfaAssessment(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: for better testability, I propose to return a status true or false instead of throwing exceptions. The printing to stdout is nice visual but testing the code sample by validating the return value is much simpler than hijacking stdout and matching the strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Returning a boolean in this case might be a bit confusing as the sample by itself has two different possible usecases and paths.

  1. reCAPTCHA is initialized for the first time and the result is unspecified which then triggers the MFA.
  2. reCAPTCHA gets the MFA token and returns the result.
    Both these flows use this sample and returning a boolean wouldn't be ideal to capture these.

But I agree that in general, it's good to use boolean for testing. Will follow up with internal discussions.

@Sita04
Copy link
Contributor Author

Sita04 commented Nov 1, 2023

Blocked by googleapis/testing-infra-docker#342

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: recaptchaenterprise Issues related to the reCAPTCHA Enterprise API. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants