Redirect to original destination after login?

Created on 21 June 2023, about 1 year ago
Updated 5 February 2024, 5 months ago

In the settings page there is Login redirect URL field with the description:

The default URL to redirect the user to after login. This should be an internal path starting with a slash, or an absolute URL. Defaults to the logged-in user's account page.

(config: samlauth.authentication.login_redirect_url)

I would like to set redirect user to the original destination instead of hardcoded one.

How can I do it?

💬 Support request
Status

Closed: works as designed

Version

3.0

Component

Code

Created by

🇷🇸Serbia g_miric

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

Comments & Activities

  • Issue created by @g_miric
  • 🇳🇱Netherlands roderik Amsterdam,NL / Budapest,HU

    This is a variation on an "Occasionally asked question" in the README:

    Redirect from /original/path to /saml/login?destination=original/path

    Note that "original destination" has no special meaning to the samlauth module.
    The module sits on /saml/login, and with "original destination", I assume you mean the path that the user visited previously, before redirecting to /saml/login. This "original path" is equivalent to any other path you want to redirect to after logging in. Which you do with saml/login?destination=any/path

  • Status changed to Closed: works as designed about 1 year ago
  • 🇷🇸Serbia g_miric

    Thanks roderik!
    That solves my issue.

  • Hello,

    I have the same issue as g_miric, but not sure how they solved the issue given your response.

    I've successfully used the login redirect url field to route users to a specific path after logging in, but I'm unsure how to make this dynamic and route to the page they were trying to visit.

    For example:

    1.user visits www.example.com/a
    2. access restricted and presented with login
    3. user successfully logs in and continues to www.example.com/a

    Thanks for helping me understand!

  • 🇳🇱Netherlands roderik Amsterdam,NL / Budapest,HU

    It's about your point 2

    2. access restricted and presented with login

    I am assuming something (outside of the samlauth module) is redirecting to /saml/login, for that purpose.

    It should be redirecting to /saml/login?destination=a instead.

  • Thank you for wording that another way. This makes a lot more sense now!

    In our case, we have a custom login block with the button pointed to /saml/login

    My next task will be to figure out how to make the button dynamic based on the current page so the button points to

    /saml/login?destination=a

    Appreciate the help!

  • 🇮🇳India suyash.vaidya Jaipur

    @bellsworth, you can use the hook_link_alter() for adding the language code as destination query parameter:

    /**
     * Implements hook_link_alter().
     */
    function module_name_link_alter(array &$variables): void {
      // Add language code as destination query string to SAML login menu link for returning user to correct language when path prefix language detection is used.
      $url = $variables['url']->toString();
      if ($url == '/saml/login') {
        $language = \Drupal::languageManager()->getCurrentLanguage()->getId();
        $variables['options']['query']['destination'] = $language;
      }
    }
    
Production build 0.69.0 2024