-
Notifications
You must be signed in to change notification settings - Fork 45
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
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 e3b929d
Add instructions to confirm_otp_token form;
strouptl f960474
move "Enable Authentication" form to separate "edit" view; reduce "sh…
strouptl 01a402f
use existing edit/update actions on otp_tokens controller for confirm…
strouptl cc9067e
remove token explanation from show page;
strouptl fed4602
update flash message for failed confirmation;
strouptl fab7c1c
move locales for OTP confirmation form to edit_otp_tokens scope; dele…
strouptl 7920bd3
differentiate title of show and edit pages; move "title" value for ed…
strouptl 5ba39da
revert method name to enable_top!;
strouptl 7074c2f
revert "h2" for otp_tokens#show to locale file;
strouptl 2b3f893
use enable_link config locale in otp_tokens#show;
strouptl ffdf493
use locales for otp_token field and submit button; switch terminology…
strouptl ebd03ca
match terminology to AWS MFA form;
strouptl debe1c1
replace remaining reference to "Verification Code";
strouptl f30aa59
add tests for enabling two-factor authentication via dedicated otp_to…
strouptl 0a9dc5a
update test helpers and initial sign_in test for new Enable Two-Facto…
strouptl 8bc2b83
update otp_tokens#update to redirect to show action as before (rather…
strouptl 074b67e
update disable test to confirm correct status displayed; remove accep…
strouptl 1e94af0
update EnableOtpForm tests to reload user before checking whether OTP…
strouptl 61f46a2
add populate_otp! method for populating initial secrets; add instruct…
strouptl e9215f4
update otp_tokens controller to populate otp secrets as needed; renam…
strouptl 747cefa
update button text and warnings for disabling 2FA; remove instruction…
strouptl 3293345
update tests for change; add otp_failed_attempts to destroy_otp_secre…
strouptl dfe9d45
rename destroy_otp_secrets! to clear_otp_fields! for consistency (sin…
strouptl 0ca939f
simplify populate_otp_secrets! method;
strouptl 51dca03
draft CHANGELOG insertion for requiring confirmation token and popula…
strouptl 04fa4a7
rename "otp_token" input to "confirmation_code"; make edit_otp_token …
strouptl 8cbc133
Update CHANGELOG.md to fix list indentation issue;
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
scaffold solution for confirming OTP before enabling OTP;
- Loading branch information
commit a83a5ddd45ecb11541765158b375b5c805c35f5c
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
app/controllers/devise_otp/devise/otp_confirm_tokens_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
module DeviseOtp | ||
module Devise | ||
class OtpConfirmTokensController < DeviseController | ||
include ::Devise::Controllers::Helpers | ||
|
||
prepend_before_action :ensure_credentials_refresh | ||
prepend_before_action :authenticate_scope! | ||
|
||
# | ||
# Displays the OTP | ||
# | ||
def show | ||
if resource.nil? | ||
redirect_to stored_location_for(scope) || :root | ||
else | ||
render "devise/otp_confirm_tokens/show" | ||
end | ||
end | ||
|
||
# | ||
# Confirms the OTP if valid | ||
# | ||
def update | ||
if resource.valid_otp_token?(params[:otp_token]) | ||
resource.confirm_otp! | ||
otp_set_flash_message :success, :successfully_updated | ||
redirect_to otp_credential_path_for(resource) | ||
else | ||
otp_set_flash_message :failure, :otp_token_does_not_match | ||
render "devise/otp_confirm_tokens/show" | ||
end | ||
end | ||
|
||
private | ||
|
||
def ensure_credentials_refresh | ||
ensure_resource! | ||
|
||
if needs_credentials_refresh?(resource) | ||
otp_set_flash_message :notice, :need_to_refresh_credentials | ||
redirect_to refresh_otp_credential_path_for(resource) | ||
end | ||
end | ||
|
||
def scope | ||
resource_name.to_sym | ||
end | ||
|
||
def self.controller_path | ||
"#{::Devise.otp_controller_path}/confirm_otp_tokens" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Confirm the OTP Token shown below: | ||
|
||
<%= otp_authenticator_token_image(resource) %> | ||
|
||
<p> | ||
<strong><%= I18n.t('manual_provisioning', :scope => 'devise.otp.token_secret') %>:</strong> | ||
<code><%= resource.otp_auth_secret %></code> | ||
</p> | ||
|
||
<%= form_with(:url => [resource_name, :otp_confirm_token], :method => :put) do |f| %> | ||
|
||
<%= f.label :otp_token %> | ||
<%= f.text_field :otp_token %> | ||
|
||
<%= f.submit :enable %> | ||
|
||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think is the broken behaviour I am seeing. Before your change you could temporarily disable OTP and I think we should preserve the functionality for the time being.