Configured Simplesaml authentication module on Drupal 9 environment. We are force redirecting the user to SAML login page (saml_login) when a user tries to access any page of the website. This is written in a custom module (.module) file. That means only logged in / authenticated users can see the website.

Some times / in few cases, we are seeing "The page isn't working, website redirected you too many times" issue after login into SAML. Probably login was successful with IDP but Drupal not able to fetch User ID quickly. If we refresh the page then User ID fetching up properly. Some times login page is redirecting user properly to home page with successful authentication.

There is no quick sync between SAML login and Drupal user data. We have tried with below codes.

$userID = \Drupal::currentUser()->id();
$is_anonymous = \Drupal::currentUser()->isAnonymous();
if ($userID == 0 && $is_anonymous == 1) {
if (!in_array($route_name,['user.login', 'user.logout', 'saml_login'])) {
$response = new RedirectResponse($base_url . '/saml_login');
$response->send();
}
}
----------------------------------------------------------------------------------------------------------------------
$simplesaml = \Drupal::service('simplesamlphp_auth.manager');
if ($simplesaml->isActivated() && $simplesaml->isAuthenticated()) {
}else{
if (!in_array($route_name,['user.login', 'user.logout', 'saml_login']) && $userID != 1) {
$response = new RedirectResponse($base_url . '/saml_login');
$response->send();
}
}

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bhanojeerao created an issue. See original summary.

miikamakarainen made their first commit to this issue’s fork.

miikamakarainen’s picture

I had the same issue today when I updated from 9.1.10 to 9.2.0 and started looking at simplesamlphp_auth as it is a login related issue but it was related to another module.

I was able to resolve the issue with replacing Redirect after login with Login destination. See issue #3214949.

bhanojeerao’s picture

Title: Too many redirects with SAML login » Too many redirects error, user considered as anonymous
Issue summary: View changes
bhanojeerao’s picture

Issue summary: View changes
bhanojeerao’s picture

I have used "anonymous_login" module and removed above redirection code, but problem persists still. Is any one familiar with this issue?