Remove after_otp_verification_confirmation_url#8498
Conversation
changelog: Internal, Refactor, Remove after_otp_verification_confirmation_url
| mark_user_session_authenticated(:device_remembered) | ||
| handle_valid_remember_device_analytics(cookie_created_at: remember_device_cookie.created_at) | ||
| redirect_to after_otp_verification_confirmation_url unless reauthn? | ||
| redirect_to after_sign_in_path_for(current_user) unless reauthn? |
There was a problem hiding this comment.
I noticed that since it's defined on application_controller, the after_sign_in_path_for method would already have access to current_user and not need it passed as an arg, but then looking at it's source, the _user is unused!
Looks like the method comes from devise but what if we redefined it to have a default value for user and then just stopped passing current_user everywhere to simplify?
| redirect_to after_sign_in_path_for(current_user) unless reauthn? | |
| redirect_to after_sign_in_path_for unless reauthn? |
def after_sign_in_path_for(_scope = nil)There was a problem hiding this comment.
I think it would be good to try this, but probably better tackled in a separate PR?
app/controllers/two_factor_authentication/otp_verification_controller.rb
Outdated
Show resolved
Hide resolved
| auth_method: params[:otp_delivery_preference], | ||
| ) | ||
| flash[:success] = t('notices.phone_confirmed') | ||
| redirect_to next_setup_path || after_mfa_setup_path |
There was a problem hiding this comment.
How was the second half of this (|| after_mfa_setup_path) happening in the previous code?
There was a problem hiding this comment.
It was happening via a combination of behavior in these methods:
identity-idp/app/controllers/application_controller.rb
Lines 232 to 247 in 22f4ab7
I think the behavior of the change is effectively zero. The order of checking for redirects is slightly different, but I don't think it could result in a different set of requests for a user after doing some testing.
The above change brings this controller in line with the other setup controllers in using redirect_to next_setup_path || after_mfa_setup_path (TOTP, Backup Codes, WebAuthn)
🛠 Summary of changes
A little bit of cleanup following #8392. The
after_otp_verification_confirmation_urlfunction only behaves differently in theOtpVerificationControllerwhen in the confirmation context due to the prior work. The@next_mfa_setup_pathand@updating_existing_numberinstance variables are only set there, which is what results in the different behavior.This PR removes those instance variables and replaces the
after_otp_verification_confirmation_urlwith the defaultafter_sign_in_path_for(current_user)in the other controllers that used it. This should not result in a change in behavior and hopefully results in a little bit less abstraction.