Conversation
|
|
||
| def valid_captcha_result? | ||
| if cookies[:device] && (device = Device.find_by(cookie_uuid: cookies[:device])) | ||
| return true if device.user.email_addresses.lazy.map(&:email).include?(auth_params[:email]) |
There was a problem hiding this comment.
oooo smart use of .lazy! Another idea:
| return true if device.user.email_addresses.lazy.map(&:email).include?(auth_params[:email]) | |
| return true if device.user.email_addresses.any? { |e| e.email == auth_params[:email] } |
There was a problem hiding this comment.
Yeah I thought it was a nice way to avoid having to use a block, but funny that the block form ends up being shorter anyways 😅
| elsif FeatureManagement.recaptcha_enterprise? | ||
| args.merge(form_class: RecaptchaEnterpriseForm) | ||
| else | ||
| args |
There was a problem hiding this comment.
should we default to RecaptchaForm for completeness?
| args | |
| args.merge(form_class: RecaptchaForm) |
There was a problem hiding this comment.
It's defaulted in SignInRecaptchaForm, so not strictly necessary:
This follows from the implementation for phone setup:
identity-idp/app/forms/new_phone_form.rb
Lines 144 to 153 in 37afb7e
But I could also change it so that form_class is a required keyword attribute and assign it here instead.
(Aside: When implementing this "proper", I'll probably plan to create a separate form class for handling the sign-in+reCAPTCHA validation, similar to what we have with NewPhoneForm)
There was a problem hiding this comment.
yeah seeing the default argument there is what prompted me to make the comment here
|
|
||
| class CaptchaSubmitButtonComponent < BaseComponent | ||
| attr_reader :form, :action, :tag_options | ||
| attr_reader :form, :action, :button_options, :tag_options |
There was a problem hiding this comment.
this is the recaptcha_action not the older link-or-button action right? What if we renamed to recapcha_action tomatch the RECAPTCHA_ACTION constant it gets called with?
There was a problem hiding this comment.
Yeah, it's the reCAPTCHA concept of "action", also documented with a reference link a couple lines below.
But sure, I think renaming recaptcha_action could be clearer / more consistent.
There was a problem hiding this comment.
Also, that link should probably reference the Enterprise documentation, which is a little more complete and matches the expected production behavior:
https://cloud.google.com/recaptcha-enterprise/docs/actions-website
| end | ||
|
|
||
| def valid_captcha_result? | ||
| if cookies[:device] && (device = Device.find_by(cookie_uuid: cookies[:device])) |
There was a problem hiding this comment.
Discussed a little bit offline, but this query should probably include a subquery on email address for the user_id since cookie_uuid is not unique.
|
This proof-of-concept has served its purpose. I'll close this for now, but it's likely we'll use parts of this for future reference. |
🛠 Summary of changes
Implements a proof-of-concept reCAPTCHA validation at sign-in.
📜 Testing Plan
👀 Screenshots