Procházet zdrojové kódy

Ask for auth if we get a 403 and did not have auth yet, fixes #2464

Jordi Boggiano před 11 roky
rodič
revize
cc7920000c
1 změnil soubory, kde provedl 19 přidání a 9 odebrání
  1. 19 9
      src/Composer/Util/RemoteFilesystem.php

+ 19 - 9
src/Composer/Util/RemoteFilesystem.php

@@ -247,13 +247,7 @@ class RemoteFilesystem
                         throw new TransportException($message, 401);
                     }
 
-                    $this->io->overwrite('    Authentication required (<info>'.parse_url($this->fileUrl, PHP_URL_HOST).'</info>):');
-                    $username = $this->io->ask('      Username: ');
-                    $password = $this->io->askAndHideAnswer('      Password: ');
-                    $this->io->setAuthentication($this->originUrl, $username, $password);
-
-                    $this->retry = true;
-                    throw new TransportException('RETRY');
+                    $this->promptAuthAndRetry();
                     break;
                 }
 
@@ -265,9 +259,14 @@ class RemoteFilesystem
 
             case STREAM_NOTIFY_AUTH_RESULT:
                 if (403 === $messageCode) {
-                    $message = "The '" . $this->fileUrl . "' URL could not be accessed: " . $message;
+                    if (!$this->io->isInteractive() || $this->io->hasAuthentication($this->originUrl)) {
+                        $message = "The '" . $this->fileUrl . "' URL could not be accessed: " . $message;
+
+                        throw new TransportException($message, 403);
+                    }
 
-                    throw new TransportException($message, 403);
+                    $this->promptAuthAndRetry();
+                    break;
                 }
                 break;
 
@@ -297,6 +296,17 @@ class RemoteFilesystem
         }
     }
 
+    protected function promptAuthAndRetry()
+    {
+        $this->io->overwrite('    Authentication required (<info>'.parse_url($this->fileUrl, PHP_URL_HOST).'</info>):');
+        $username = $this->io->ask('      Username: ');
+        $password = $this->io->askAndHideAnswer('      Password: ');
+        $this->io->setAuthentication($this->originUrl, $username, $password);
+
+        $this->retry = true;
+        throw new TransportException('RETRY');
+    }
+
     protected function getOptionsForUrl($originUrl, $additionalOptions)
     {
         $headers = array(