Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cc79200

Browse files
committed
Ask for auth if we get a 403 and did not have auth yet, fixes composer#2464
1 parent 1d0cc93 commit cc79200

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

src/Composer/Util/RemoteFilesystem.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,7 @@ protected function callbackGet($notificationCode, $severity, $message, $messageC
247247
throw new TransportException($message, 401);
248248
}
249249

250-
$this->io->overwrite(' Authentication required (<info>'.parse_url($this->fileUrl, PHP_URL_HOST).'</info>):');
251-
$username = $this->io->ask(' Username: ');
252-
$password = $this->io->askAndHideAnswer(' Password: ');
253-
$this->io->setAuthentication($this->originUrl, $username, $password);
254-
255-
$this->retry = true;
256-
throw new TransportException('RETRY');
250+
$this->promptAuthAndRetry();
257251
break;
258252
}
259253

@@ -265,9 +259,14 @@ protected function callbackGet($notificationCode, $severity, $message, $messageC
265259

266260
case STREAM_NOTIFY_AUTH_RESULT:
267261
if (403 === $messageCode) {
268-
$message = "The '" . $this->fileUrl . "' URL could not be accessed: " . $message;
262+
if (!$this->io->isInteractive() || $this->io->hasAuthentication($this->originUrl)) {
263+
$message = "The '" . $this->fileUrl . "' URL could not be accessed: " . $message;
264+
265+
throw new TransportException($message, 403);
266+
}
269267

270-
throw new TransportException($message, 403);
268+
$this->promptAuthAndRetry();
269+
break;
271270
}
272271
break;
273272

@@ -297,6 +296,17 @@ protected function callbackGet($notificationCode, $severity, $message, $messageC
297296
}
298297
}
299298

299+
protected function promptAuthAndRetry()
300+
{
301+
$this->io->overwrite(' Authentication required (<info>'.parse_url($this->fileUrl, PHP_URL_HOST).'</info>):');
302+
$username = $this->io->ask(' Username: ');
303+
$password = $this->io->askAndHideAnswer(' Password: ');
304+
$this->io->setAuthentication($this->originUrl, $username, $password);
305+
306+
$this->retry = true;
307+
throw new TransportException('RETRY');
308+
}
309+
300310
protected function getOptionsForUrl($originUrl, $additionalOptions)
301311
{
302312
$headers = array(

0 commit comments

Comments
 (0)