-
Notifications
You must be signed in to change notification settings - Fork 18
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: add recaptcha functionality to API registration #574
Conversation
Coverage of commit
|
Coverage of commit
|
@bklebe @paulswartz Do either of you have an opinion on how to handle the updated library assuming the external PR does not get merged? I am leaning towards just copying the code, with documentation in the README or something like that. |
Coverage of commit
|
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.
If it's not merged upstream, we can fork it into the mbta
organization. We've done that for other dependencies in the past, and it'll probably help the MBTA.com team in the future as well.
apps/api_web/lib/api_web/templates/client_portal/user/_new.html.heex
Outdated
Show resolved
Hide resolved
…l.heex Co-authored-by: Paul Swartz <[email protected]>
Coverage of commit
|
Coverage of commit
|
Coverage of commit
|
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.
apps/api_web/config/config.exs
Outdated
public_key: {:system, "RECAPTCHA_PUBLIC_KEY"}, | ||
secret: {:system, "RECAPTCHA_PRIVATE_KEY"} |
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.
suggestion: for dynamic configuration, we typically load it using System.get_env/2
in config/runtime.exs
now.
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.
suggestion: for dynamic configuration, we typically load it using
System.get_env/2
inconfig/runtime.exs
now.
I added the env vars to that file, and added a feature flag to disable the recaptcha code outside of prod builds.
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 tried it out, and the first thing I noticed was that the form fields were cleared if I submitted without the captcha. Otherwise it seems to work well.
I added some frontend code to only enable the submit button once the user completes the recaptcha, so this won't happen outside of someone attempting to do something weird.
Deployed to dev-green 🙂
Coverage of commit
|
This is available for review on |
I tried it out, and the first thing I noticed was that the form fields were cleared if I submitted without the captcha. Otherwise it seems to work well. |
Coverage of commit
|
Coverage of commit
|
Coverage of commit
|
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.
question: should there be some tests?
|> put_session(:user_id, user.id) | ||
|> configure_session(renew: true) | ||
|> redirect(to: portal_path(conn, :index)) | ||
_create(conn, user_params, nil) |
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.
suggestion(non-blocking): You could combine these with Map.get
which defaults to nil
:
def create(conn, %{"user" => user_params} = params) do
recaptcha = Map.get(params, "g-recaptcha-response")
...
end
Co-authored-by: Paul Swartz <[email protected]>
Coverage of commit
|
Coverage of commit
|
Definitely! I added one that proves that the widget shows up when supplying the test creds: https://github.com/mbta/api/pull/574/files#diff-740356136f3337b207b35a2c46f8b47dcab0944918c977f6e8e0d04bd9eab52dR11. Due to the nature of ReCaptcha, a true end to end test isn't feasible, but this should ensure the path it takes is laid out correctly if that makes sense 🙂 |
Coverage of commit
|
@paulswartz I accepted your proposed change on one of your comments so the conversation got swallowed, but with regard to the I went with But really, we should only ever evaluate whether it gives |
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.
🍰
Summary of changes
Asana Ticket: 🍎 Add recaptcha to signing up for API
This PR adds recaptcha functionality to the API, and implements it on the non-admin user create form.
A specific commit is pinned for the included library because the older published version causes dependency resolution issues.
NOTE: Before releasing this feature, we must create recaptcha keys on a production/shared Google account, and add the following environment variables to the various deployments:
RECAPTCHA_PUBLIC_KEY
,RECAPTCHA_PRIVATE_KEY
.