Browse Source

fix a bug that prevents be user to login because of bad cookie setting

Olivier Massot 4 years ago
parent
commit
7bab557635
1 changed files with 8 additions and 6 deletions
  1. 8 6
      ot_connect/Classes/Service/OtAuthenticationService.php

+ 8 - 6
ot_connect/Classes/Service/OtAuthenticationService.php

@@ -189,11 +189,8 @@ class OtAuthenticationService extends AbstractAuthenticationService
      * Update the guzzle cookie jar with the current session's ones
      */
     private function fillCookieJar() {
-
         foreach (['BEARER', 'SFSESSID'] as $cookieName) {
-            if (array_key_exists($cookieName, $_COOKIE) &&
-                $this->jar->getCookieByName($cookieName) == null) {
-
+            if (array_key_exists($cookieName, $_COOKIE)) {
                 $cookie = new SetCookie();
                 $cookie->setName($cookieName);
                 $cookie->setValue($_COOKIE[$cookieName]);
@@ -251,11 +248,16 @@ class OtAuthenticationService extends AbstractAuthenticationService
             $value = $cookie->getValue();
             $expires = $cookie->getExpires();
             $path = $cookie->getPath();
-            $domain = $_SERVER['HTTP_HOST'];
             $secure = $cookie->getSecure();
             $httpOnly = $cookie->getHttpOnly();
 
-            setcookie($name, $value, $expires, $path, $domain, $secure, $httpOnly);
+            $_COOKIE[$name] = $value;
+            setcookie($name, $value, $expires, $path, self::COOKIE_DOMAIN, $secure, $httpOnly);
+            setcookie($name, $value, $expires, $path, '.' . self::COOKIE_DOMAIN, $secure, $httpOnly);
+
+            if (!preg_match('/(.*\.)?opentalent\.fr/', $_SERVER['HTTP_HOST'])) {
+                setcookie($name, $value, $expires, $path, $_SERVER['HTTP_HOST'], $secure, $httpOnly);
+            }
         }
     }