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

Confirm OTP Token #72

Merged
merged 28 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a83a5dd
scaffold solution for confirming OTP before enabling OTP;
strouptl May 13, 2024
e3b929d
Add instructions to confirm_otp_token form;
strouptl May 13, 2024
f960474
move "Enable Authentication" form to separate "edit" view; reduce "sh…
strouptl May 13, 2024
01a402f
use existing edit/update actions on otp_tokens controller for confirm…
strouptl May 13, 2024
cc9067e
remove token explanation from show page;
strouptl May 15, 2024
fed4602
update flash message for failed confirmation;
strouptl May 15, 2024
fab7c1c
move locales for OTP confirmation form to edit_otp_tokens scope; dele…
strouptl May 15, 2024
7920bd3
differentiate title of show and edit pages; move "title" value for ed…
strouptl May 15, 2024
5ba39da
revert method name to enable_top!;
strouptl May 17, 2024
7074c2f
revert "h2" for otp_tokens#show to locale file;
strouptl May 17, 2024
2b3f893
use enable_link config locale in otp_tokens#show;
strouptl May 17, 2024
ffdf493
use locales for otp_token field and submit button; switch terminology…
strouptl May 17, 2024
ebd03ca
match terminology to AWS MFA form;
strouptl May 17, 2024
debe1c1
replace remaining reference to "Verification Code";
strouptl May 17, 2024
f30aa59
add tests for enabling two-factor authentication via dedicated otp_to…
strouptl May 18, 2024
0a9dc5a
update test helpers and initial sign_in test for new Enable Two-Facto…
strouptl May 18, 2024
8bc2b83
update otp_tokens#update to redirect to show action as before (rather…
strouptl May 18, 2024
074b67e
update disable test to confirm correct status displayed; remove accep…
strouptl May 18, 2024
1e94af0
update EnableOtpForm tests to reload user before checking whether OTP…
strouptl May 18, 2024
61f46a2
add populate_otp! method for populating initial secrets; add instruct…
strouptl May 19, 2024
e9215f4
update otp_tokens controller to populate otp secrets as needed; renam…
strouptl May 19, 2024
747cefa
update button text and warnings for disabling 2FA; remove instruction…
strouptl May 19, 2024
3293345
update tests for change; add otp_failed_attempts to destroy_otp_secre…
strouptl May 19, 2024
dfe9d45
rename destroy_otp_secrets! to clear_otp_fields! for consistency (sin…
strouptl May 19, 2024
0ca939f
simplify populate_otp_secrets! method;
strouptl May 19, 2024
51dca03
draft CHANGELOG insertion for requiring confirmation token and popula…
strouptl May 20, 2024
04fa4a7
rename "otp_token" input to "confirmation_code"; make edit_otp_token …
strouptl May 20, 2024
8cbc133
Update CHANGELOG.md to fix list indentation issue;
May 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rename "otp_token" input to "confirmation_code"; make edit_otp_token …
…scope singular; fix spelling issue in "Enable Two Factor Authentication" link; expand "Changes to Locales" description in CHANGELOG;
  • Loading branch information
strouptl committed May 20, 2024
commit 04fa4a7a4dd0e81dde06545f65bb15827c728448
33 changes: 24 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,40 @@

Summary:
- Require confirmation token before enabling Two Factor Authentication (2FA) to ensure that user has added OTP token properly to their device
- Update system to populate OTP secrets only as needed
- Update system to populate OTP secrets as needed

Changes:
Details:
- Add "edit" action with Confirmation Token for enabling 2FA to otp_tokens controller
- Make enabling of 2FA in update action conditional on valid Confirmation Token
- Repurpose "show" view for display of OTP status and info (no form)

- Update otp_tokens#edit to populate OTP secrets (rather than assuming they are populated via callbacks in OTPDeviseAuthenticatable module)
- Repurpose otp_tokens#destroy to disable 2FA and clear OTP secrets (rather than resetting them)

- Remove callbacks for setting OTP credentials on create action (no longer needed)
- Replace "reset_otp_credentials" methods with "clear_otp_fields!" method;
- Remove OtpAuthenticatable callbacks for setting OTP credentials on create action (no longer needed)
- Replace OtpAuthenticatable "reset_otp_credentials" methods with "clear_otp_fields!" method;

Changes to Locales:
- Move OTP explanation and form related values to devise.otp.edit_otp_tokens scope
- Rename devise.otp.token_secret.reset_\* values to ...disable_\*
- Rename "successfully_reset_creds" value to "successfully_disabled_otp"
- Add "enable_link" and "could_not_confirm" to otp_tokens scope
- Add "lead_in", "step1", "step2", and "otp_token" to edit_otp_tokens scope
- Remove:
- otp_tokens.enable_request
- otp_tokens.status
- otp_tokens.submit
- Add to otp_tokens scope:
- enable_link
- Move/rename devise.otp.token_secret.reset_\* values to devise.otp.otp_tokens.disable_\* (to match new "enable_link")
- disable_link
- disable_explain
- disable_explain_warn
- Add to new edit_otp_token scope:
- title
- lead_in
- step1
- step2
- confirmation_code
- submit
- Move "explain" to new edit_otp_token scope
- Add devise.otp.otp_tokens.could_not_confirm
- Rename "successfully_reset_creds" to "successfully_disabled_otp"

## 0.4.0

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/devise_otp/devise/otp_tokens_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def edit
# Updates the status of OTP authentication
#
def update
if resource.valid_otp_token?(params[:otp_token])
if resource.valid_otp_token?(params[:confirmation_code])
resource.enable_otp!
otp_set_flash_message :success, :successfully_updated
redirect_to action: :show
Expand Down
6 changes: 3 additions & 3 deletions app/views/devise/otp_tokens/_token_secret.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<code><%= resource.otp_auth_secret %></code>
</p>

<p><%= button_to I18n.t('disable_otp', :scope => 'devise.otp.token_secret'), @resource, :method => :delete, :data => { "turbo-method": "DELETE" } %></p>
<p><%= button_to I18n.t('disable_link', :scope => 'devise.otp.otp_tokens'), @resource, :method => :delete, :data => { "turbo-method": "DELETE" } %></p>

<p>
<%= I18n.t('disable_explain', :scope => 'devise.otp.token_secret') %>
<strong><%= I18n.t('disable_explain_warn', :scope => 'devise.otp.token_secret') %></strong>
<%= I18n.t('disable_explain', :scope => 'devise.otp.otp_tokens') %>
<strong><%= I18n.t('disable_explain_warn', :scope => 'devise.otp.otp_tokens') %></strong>
</p>

<%- if recovery_enabled? %>
Expand Down
16 changes: 8 additions & 8 deletions app/views/devise/otp_tokens/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<h2><%= I18n.t('title', :scope => 'devise.otp.edit_otp_tokens') %></h2>
<p><%= I18n.t('explain', :scope => 'devise.otp.edit_otp_tokens') %></p>
<h2><%= I18n.t('title', :scope => 'devise.otp.edit_otp_token') %></h2>
<p><%= I18n.t('explain', :scope => 'devise.otp.edit_otp_token') %></p>

<h2><%= I18n.t('lead_in', :scope => 'devise.otp.edit_otp_tokens') %></h2>
<h2><%= I18n.t('lead_in', :scope => 'devise.otp.edit_otp_token') %></h2>

<p><%= I18n.t('step_1', :scope => 'devise.otp.edit_otp_tokens') %></p>
<p><%= I18n.t('step_1', :scope => 'devise.otp.edit_otp_token') %></p>

<%= otp_authenticator_token_image(resource) %>

Expand All @@ -12,15 +12,15 @@
<code><%= resource.otp_auth_secret %></code>
</p>

<p><%= I18n.t('step_2', :scope => 'devise.otp.edit_otp_tokens') %></p>
<p><%= I18n.t('step_2', :scope => 'devise.otp.edit_otp_token') %></p>

<%= form_with(:url => [resource_name, :otp_token], :method => :put) do |f| %>

<p>
<%= f.label :otp_token, I18n.t('otp_token', :scope => 'devise.otp.edit_otp_tokens') %>
<%= f.text_field :otp_token %>
<%= f.label :confirmation_code, I18n.t('confirmation_code', :scope => 'devise.otp.edit_otp_token') %>
<%= f.text_field :confirmation_code %>
</p>

<p><%= f.submit I18n.t('submit', :scope => 'devise.otp.edit_otp_tokens') %></p>
<p><%= f.submit I18n.t('submit', :scope => 'devise.otp.edit_otp_token') %></p>

<% end %>
12 changes: 6 additions & 6 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ en:
title: 'Your token secret'
explain: 'Take a photo of this QR code with your mobile'
manual_provisioning: 'Manual provisioning code'
disable_otp: 'Disable Two-Factor Authentication'
disable_explain: 'This will disable Two-Factor authentication and clear the OTP secret.'
disable_explain_warn: 'To re-enable Two-Factor authentication, you will need to enroll your mobile device again.'
otp_tokens:
title: 'Two-factors Authentication:'
enable_link: 'Enable Two-Factors Authentication'
enable_link: 'Enable Two-Factor Authentication'
disable_link: 'Disable Two-Factor Authentication'
disable_explain: 'This will disable Two-Factor authentication and clear the OTP secret.'
disable_explain_warn: 'To re-enable Two-Factor authentication, you will need to enroll your mobile device again.'
successfully_updated: 'Your two-factors authentication settings have been updated.'
could_not_confirm: 'The Confirmation Code you entered did not match the QR code shown below.'
successfully_disabled_otp: 'Two-Factor authentication has been disabled.'
Expand All @@ -46,13 +46,13 @@ en:
code: 'Recovery Code'
codes_list: 'Here is the list of your recovery codes'
download_codes: 'Download recovery codes'
edit_otp_tokens:
edit_otp_token:
title: 'Enable Two-factors Authentication'
explain: 'Two factors authentication adds an additional layer of security to your account. When logging in you will be asked for a code that you can generate on a physical device, like your phone.'
lead_in: 'To Enable Two-Factor Authentication:'
step_1: '1. Open your authenticator app and scan the QR code shown below:'
step_2: '2. Enter the 6-digit code shown in your authenticator app below:'
otp_token: "Confirmation Code"
confirmation_code: "Confirmation Code"
submit: 'Continue...'
trusted_browsers:
title: 'Trusted Browsers'
Expand Down
6 changes: 3 additions & 3 deletions test/integration/enable_otp_form_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def teardown

user.reload

fill_in "otp_token", with: ROTP::TOTP.new(user.otp_auth_secret).at(Time.now)
fill_in "confirmation_code", with: ROTP::TOTP.new(user.otp_auth_secret).at(Time.now)

click_button "Continue..."

Expand All @@ -29,7 +29,7 @@ def teardown

visit edit_user_otp_token_path

fill_in "otp_token", with: "123456"
fill_in "confirmation_code", with: "123456"

click_button "Continue..."

Expand All @@ -44,7 +44,7 @@ def teardown

visit edit_user_otp_token_path

fill_in "otp_token", with: ""
fill_in "confirmation_code", with: ""

click_button "Continue..."

Expand Down
2 changes: 1 addition & 1 deletion test/integration/sign_in_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def teardown
visit user_otp_token_path
assert page.has_content?("Disabled")

click_link "Enable Two-Factors Authentication"
click_link "Enable Two-Factor Authentication"

assert page.has_content?("Enable Two-factors Authentication")
assert_equal edit_user_otp_token_path, current_path
Expand Down
2 changes: 1 addition & 1 deletion test/integration_tests_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def enable_otp_and_sign_in

sign_user_in(user)
visit edit_user_otp_token_path
fill_in "otp_token", with: ROTP::TOTP.new(user.otp_auth_secret).at(Time.now)
fill_in "confirmation_code", with: ROTP::TOTP.new(user.otp_auth_secret).at(Time.now)
click_button "Continue..."

Capybara.reset_sessions!
Expand Down
Loading