Index: src/Service/SimplesamlphpAuthManager.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/Service/SimplesamlphpAuthManager.php b/src/Service/SimplesamlphpAuthManager.php
--- a/src/Service/SimplesamlphpAuthManager.php	(revision 8951ac2bdfd84447cdf8dbe9b76e710042ea7fb4)
+++ b/src/Service/SimplesamlphpAuthManager.php	(date 1684955353040)
@@ -14,6 +14,7 @@
 use Drupal\Core\Extension\ModuleHandlerInterface;
 use Symfony\Component\HttpFoundation\RequestStack;
 use Drupal\Core\Messenger\MessengerInterface;
+use Symfony\Component\HttpFoundation\Response;

 /**
  * Service to interact with the SimpleSAMLPHP authentication library.
@@ -119,7 +120,7 @@
   /**
    * Forwards the user to the IdP for authentication.
    */
-  public function externalAuthenticate() {
+  public function externalAuthenticate(): bool|null|Response {
     $uri = $this->requestStack->getCurrentRequest()->getUri();

     $instance = $this->getSimpleSamlInstance();
@@ -128,7 +129,7 @@
       return FALSE;
     }

-    $instance->requireAuth(['ReturnTo' => $uri]);
+    return $instance->requireAuth(['ReturnTo' => $uri]);
   }

   /**
Index: src/Controller/SimplesamlphpAuthController.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/Controller/SimplesamlphpAuthController.php b/src/Controller/SimplesamlphpAuthController.php
--- a/src/Controller/SimplesamlphpAuthController.php	(revision 8951ac2bdfd84447cdf8dbe9b76e710042ea7fb4)
+++ b/src/Controller/SimplesamlphpAuthController.php	(date 1684955353029)
@@ -6,6 +6,7 @@
 use Drupal\Core\Controller\ControllerBase;
 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
 use Drupal\Core\Path\PathValidatorInterface;
+use Drupal\Core\Routing\TrustedRedirectResponse;
 use Drupal\Core\Routing\UrlGeneratorInterface;
 use Drupal\Core\Session\AccountInterface;
 use Drupal\simplesamlphp_auth\Service\SimplesamlphpAuthManager;
@@ -15,6 +16,7 @@
 use Symfony\Component\HttpFoundation\RequestStack;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 use Drupal\Core\Config\ConfigFactoryInterface;
+use Symfony\Component\HttpFoundation\Response;

 /**
  * Controller routines for simplesamlphp_auth routes.
@@ -197,7 +199,10 @@
         header('Cache-Control: no-cache');
       }

-      $this->simplesaml->externalAuthenticate();
+      $response = $this->simplesaml->externalAuthenticate();
+      if ($response instanceof Response && $response->getStatusCode() === 303) {
+        return new TrustedRedirectResponse($response->headers->get('Location'), $response->getStatusCode());
+      }
     }

     // Check to see if we've set a cookie. If there is one, give it priority.
