1
0
Fork 0

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

pull/2326/head
Jordi Boggiano 2013-12-31 15:31:03 +01:00
parent 1d0cc93fbb
commit cc7920000c
1 changed files with 19 additions and 9 deletions

View File

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