Skip to content

Refactor handling of successful two-factor phone confirmation#8347

Merged
mitchellhenke merged 1 commit intomainfrom
mitchellhenke/handle-valid-verification-consolidation
May 8, 2023
Merged

Refactor handling of successful two-factor phone confirmation#8347
mitchellhenke merged 1 commit intomainfrom
mitchellhenke/handle-valid-verification-consolidation

Conversation

@mitchellhenke
Copy link
Contributor

🛠 Summary of changes

A bit of a followup to #8178 and #8316 (specifically this comment) to start consolidating how we implement handle_valid_otp. We have repeated ourselves a few times with methods like mark_user_as_fully_authenticated, but there's a significant amount of phone-specific functionality now. This PR starts to separate those, and aims to eventually consolidate into handle_valid_2FA or similar since not all 2FAs have an OTP (which makes handle_valid_otp kind of misleading).

changelog: Internal, Two-Factor Authentication, Refactor handling of successful two-factor phone confirmation
@mitchellhenke mitchellhenke requested a review from aduth May 5, 2023 17:00
@mitchellhenke mitchellhenke marked this pull request as ready for review May 5, 2023 18:11
handle_valid_otp_for_authentication_context(auth_method: auth_method)
elsif UserSessionContext.confirmation_context?(context)
handle_valid_otp_for_confirmation_context
handle_valid_verification_for_confirmation_context
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify my understanding, currently this only happens for phones, but eventually we'd want this method to be called for any MFA in the confirmation context?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s my plan, yeah

Copy link
Contributor

@aduth aduth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

post_analytics(result)
if result.success?
handle_valid_confirmation_otp if UserSessionContext.confirmation_context?(context)
handle_valid_otp(next_url: nil, auth_method: params[:otp_delivery_preference])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to pull handle_valid_otp into this class? And then maybe consolidate this to a single "handle_valid_*" call?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

session context really only exists for phone OTPs, so I'm leaning towards making the handle_valid_confirmation/handle_valid_authentication calls explicit, and the phone controller can have the conditional checks with UserSessionContext.confirmation_context?, etc.

I'm ultimately hoping this controller will be something like:

if UserSessionContext.confirmation_context?(context)
  handle_valid_confirmation_otp
  handle_valid_verification_for_confirmation
else
  handle_valid_verification_for_authentication
end

and the remaining auth controllers can call handle_valid_verification_for_confirmation / handle_valid_verification_for_authentication without using session context since the controller action should be enough to know the difference.

@mitchellhenke mitchellhenke merged commit 3934431 into main May 8, 2023
@mitchellhenke mitchellhenke deleted the mitchellhenke/handle-valid-verification-consolidation branch May 8, 2023 13:54
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