Problem/Motivation

Currently if you try to login via the block (which requires this patch #2927125: Fatal error on TfaUserLoginBlock, you just stay in the same page, not logged, when you should be getting redirected to the 2fa page.
This is due to he fact that the login form has a destination in place.

Proposed resolution

Remove the destination, and attach it to the redirect so it isn’t lost.

Remaining tasks

Do it.

User interface changes

None

API changes

None

Data model changes

None

Comments

Manuel Garcia created an issue. See original summary.

manuel garcia’s picture

Title: TfaLoginBlock not redirecting to the TFA page » TfaLoginBlock not redirecting to the 2FA page
manuel garcia’s picture

Status: Active » Needs review
StatusFileSize
new699 bytes

Status: Needs review » Needs work

The last submitted patch, 3: 2927816-3.patch, failed testing. View results

manuel garcia’s picture

Status: Needs work » Needs review
daggerhart’s picture

StatusFileSize
new689 bytes
new413 bytes

Thanks for the work! I needed to make a minor adjustment. The destination needed to be passed into the url parameters rather than the url "options".

Note: as-written, this will also add a destination when using the normal login form. The destination will be /user/login, and this doesn't cause any problems with logging, but I thought it was worth mentioning.

therealssj’s picture

Status: Needs review » Reviewed & tested by the community

Tested against the latest branch.
This would be a nice change to have in the next release. Lets get this in!

daggerhart’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.01 KB

After some discussion in slack, @therealssj and I thought it better to have this patch not change the outcome of where the user ends up after logging in using the normal login form at /user/login.

This patch ignores the destination if it is set to /user/login. Feedback welcome.

manuel garcia’s picture

re #6: good catch!
re #8: Not highly opinionated about this, but isn’t it vanilla Drupal behaviour to send the user to their user page if logging in from the /user/login page without any destinations? If we alter that behaviour, site's that are used to it will definitely notice this change, and may want to correct this.

daggerhart’s picture

StatusFileSize
new689 bytes

@manuel-garcia you're right, thanks! I just tested a vanilla Drupal login and landed on the user/1 page. Here is the patch re-rolled against 8.x-1.x (some line numbers changed) without the special case for /user/login.

daggerhart’s picture

StatusFileSize
new3.39 KB

Updated the patch to use dependency injection for the redirect.destination and request services.

manuel garcia’s picture

Status: Needs review » Reviewed & tested by the community

Re #11: we're only using those in one place but oh well, works for me!
Back to RTBC then.

benjifisher’s picture

Status: Reviewed & tested by the community » Needs work

@Manuel Garcia:

I requested the DI on Slack. I think that will make this login block easier to test, which is more important than how many times the objects are used.

Testing

Before applying the patch, I enabled the TFA Login block and tested with two users:

  1. A user with TFA set up does not get logged in, nor redirected to the TFA form.
  2. A user without TFA set up does get logged in.

In both cases, the current page reloads after submitting the form.

After applying the patch,

  1. A user with TFA set up is redirected to the form for entering an application verification code. After entering the code, the user is logged in.
  2. A user without TFA set up is logged in directly.

In both cases, the current page reloads after submitting the form.

Code review

1. There is a mismatch. We want a RequestStack object, not a Request:

  /**
   * Current Request object.
   *
   * @var \Symfony\Component\HttpFoundation\Request
   */
  protected $request;

Please update the description as well as the type.

2. Just a suggestion, you can leave this as is if you want.

        $form_state->setRedirect(
          'tfa.entry',
          [
            'user' => $account->id(),
            'hash' => $login_hash,
          ] + $destination
        );

I think this version will work exactly the same, and is a little easier to read:

	$destination['user'] = $account->id();
	$destination['hash'] = $login_hash;
        $form_state->setRedirect('tfa.entry', $destination);
benjifisher’s picture

As we discussed on Slack, my first requested change was off the mark, but it would be more consistent to call getCurrentRequest() in the create() method.

daggerhart’s picture

Status: Needs work » Needs review
StatusFileSize
new3.65 KB

Thanks @benjifisher, I really appreciate the specific code suggestions.

1. As discussed on slack, I've modified the create() method to return the request from the request_stack.

2. I agree this is more clean. The new patch does what you suggest.

benjifisher’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new2.87 KB

I re-tested and reviewed the changes. Looks good!

I am attaching an interdiff comparing the two patches that I reviewed.

manuel garcia’s picture

patch looking beautiful, great work guys! rtbc++

  • nerdstein committed fcf3f5e on 8.x-1.x authored by daggerhart
    Issue #2927816 by daggerhart, Manuel Garcia, benjifisher: TfaLoginBlock...
nerdstein’s picture

Status: Reviewed & tested by the community » Fixed

The patch in 15 looks great. Merging!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

ginovski’s picture

Is this fixed currently?
I set up a GA Login plugin and still not getting redirected to the entry form, but instead to the homepage and not logged in.
Maybe I am missing some step in the setup, any hints?