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

Fix Mandatory OTP Issue #78

Merged
merged 10 commits into from
May 30, 2024
Merged

Fix Mandatory OTP Issue #78

merged 10 commits into from
May 30, 2024

Conversation

strouptl
Copy link
Contributor

@strouptl strouptl commented May 25, 2024

@strzibny, here is the completed mandatory_otp solution. It resolves the main issue where mandatory otp can be skipped in Issue #71. Please let me know your thoughts!

(Excerpted from CHANGELOG)
Summary: Move mandatory OTP functionality to the helper layer to ensure that it is enforced throughout application (rather than one time at log in).

Details:

  • Add PublicHelpers class, and add to Devise @@helpers variable to generate per-scope ensure_mandatory_{scope}_otp! methods;
  • Update order of module definitions and "require" statements in devise-otp.rb (required for adding DeviseOtpAuthenticable PublicHelpers to Devise @@helpers variable);

Breaking Changes:

  • Requires adding "ensure_mandatory_{scope}_otp! to controllers;

…ensure that Devise mappings are populated before calling define_helpers;
…pers! method; move DeviseOtpAuthenticable module above Devise module modifications to ensure that PublicHelpers class is available; append "on_load" callback to devise-otp file to ensure that updated helpers are included;
@strzibny
Copy link
Collaborator

I too was thinking of moving it outside the session controller, looks good as an approach.

@strouptl
Copy link
Contributor Author

strouptl commented May 25, 2024

OK, good. The meta programming was the tricky part for me: the Mappings have to be defined before calling the "define_helpers" method in order to generate the per-mapping routes.

Here are the approaches I considered (for reference):

  1. Add the new DeviseOtpAuthenticable PublicHelpers class to the @@helpers variable (current_approach)
  2. Overwrite Devise's "regnerate_routes!" method (as this gets called after defining the routes)
  3. Update the Devise::Controller::Helper's own define_routes method (inserting the ensure_mandatory_{scope}_otp! definition inline with the authenticate_{scope}! method)

I don't know if you know of a better way, but the first seemed the least intrusive to me.

@strzibny strzibny merged commit 62584a2 into wmlele:master May 30, 2024
1 check passed
@strouptl strouptl deleted the mandatory_otp branch June 4, 2024 12:39
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