Create a hook to set the destination path after authentication.

Created on 20 April 2022, about 2 years ago
Updated 21 May 2024, about 1 month ago

Problem/Motivation

There is currently not an easy to way to set the destination path after a user is authenticated.

The standard redirect method of using hook_form_alter() and $form_state->setRedirect() does not work.
The alternative is to use hook_login() but we can not just issue a redirect there because the login process might break (subsequent hook_login will not be executed). According to a discussion here πŸ› Headers have already been sent after upgrade to Drupal 9.2 (can't login) Needs review the right way with hook_login would be to create a middleware which is an overkill.

Proposed resolution

I am proposing to create a hook alter in the OpenIDConnectSession::saveDestination() that enables the developers to alter the $path and $query parameters before they are added to the $_SESSION['openid_connect_destination'] variable.

✨ Feature request
Status

Needs work

Version

1.0

Component

Code

Created by

πŸ‡¬πŸ‡·Greece msti Heraklion

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¨πŸ‡¦Canada liquidcms

    Thanks @msti for answering. Your patch no longer applies to the 3.2 branch; plus i don't think they handle redirecting the same way now (although don't see any way of altering this either).

  • πŸ‡¨πŸ‡¦Canada liquidcms

    I'm tempted to simply add this line in OpenIDConnectRedirectController.php

        // @see \Drupal\openid_connect\OpenIDConnectSessionInterface::saveDestination()
        $session = $this->session->retrieveDestination();
        $destination = $session['destination'] ?: $this->configFactory->get('openid_connect.settings')->get('redirect_login');
    
        // Add Alter to allow modules modifying the destination.
        $destination = $this->moduleHandler
          ->invokeAll('openid_connect_login_redirect', [$destination])[0];

    but suspect some method already exists to do this?

  • πŸ‡©πŸ‡ͺGermany zuernBernhard

    no - that would be nice :-)

Production build 0.69.0 2024