Skip to content

Redirect to sign in from authentication controllers#8173

Merged
aduth merged 8 commits intomainfrom
aduth-request-id-init-redirect
Apr 19, 2023
Merged

Redirect to sign in from authentication controllers#8173
aduth merged 8 commits intomainfrom
aduth-request-id-init-redirect

Conversation

@aduth
Copy link
Contributor

@aduth aduth commented Apr 11, 2023

🛠 Summary of changes

Updates the logic for redirecting during a partner-initiated authentication in order to remove the request_id query parameter, since the request ID will have already been saved to the session at this point.

This is a follow-up to #8137 (comment) :

I started exploring removing the request_id from the redirects initiated by SamlIdpController and OpenidConnect::AuthorizationController, since the request_id will have already been stored at those points, via store_saml_request and store_request respectively. I think there's definitely some simplification that can be done here, particularly with removing the argument to confirm_two_factor_authenticated and maybe even the first line of that method. But it's a bit more involved since the Warden authenticate_user! will cause an alert banner to be shown on the Sign In screen without that first line of the method.

📜 Testing Plan

  • Confirm that you can sign in from a service provider, and that the Sign In screen maintains the branded experience and does not include any unexpected alert banners (e.g. "Your session has expired")

Copy link
Contributor

@mitchellhenke mitchellhenke left a comment

Choose a reason for hiding this comment

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

This rules 👏🏼 👏🏼 👏🏼 👏🏼 👏🏼

Comment on lines 56 to 59
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Couple thoughts:

  • Maybe the device expired should take priority here (at least if checking second-factor), if it was running as the last thing in the method previously?
  • Is user_fully_authenticated? still accurate with the new redirect and removal of the MFA policy method? Or should the user only be redirected to sign in if there's no sign-in at all (i.e. haven't entered username/password)
Suggested change
if !user_fully_authenticated?
redirect_to new_user_session_url
elsif remember_device_expired_for_sp?
redirect_to user_two_factor_authentication_url
if !user_signed_in?
redirect_to new_user_session_url
elsif remember_device_expired_for_sp?
redirect_to user_two_factor_authentication_url

Copy link
Contributor

Choose a reason for hiding this comment

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

The case where user_fully_authenticated? is false and user_signed_in? would happen if there was an email/password auth, but not 2FA? I think it would be fine to be stricter and switch to user_signed_in?

I think the elsif would have to change though:

- elsif remember_device_expired_for_sp?
+ elsif user_fully_authenticated? && remember_device_expired_for_sp?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, yeah, you might be right about that. I pushed the first half in f86ff64, but curious to see if any existing tests fail, and will dig into overlap between remember device + fully authenticated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added back the user_fully_authenticated? in 0e95583, and later refactored in d72c270 to try to get even closer to the initial logic.

aduth and others added 3 commits April 12, 2023 08:27
Avoid unnecessary request_id query parameter and associated logic

changelog: Internal, Authentication, Remove request_id query parameter when redirecting to Sign In
See: https://github.com/18F/identity-idp/pull/8173/files#r1162986549

This is also more similar to how it behaved previously in ApplicationController#user_needs_new_session_with_request_id?
@aduth aduth force-pushed the aduth-request-id-init-redirect branch from 101fbdd to 17e0755 Compare April 12, 2023 12:28
aduth added 3 commits April 12, 2023 10:46
See: #8173 (comment)

Maintain consistency with prior implementation
Allows better control over how confirm_two_factor_authenticated is called in sequence with other relevant checks
@aduth aduth merged commit 9c2ea48 into main Apr 19, 2023
@aduth aduth deleted the aduth-request-id-init-redirect branch April 19, 2023 12:42
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