function DiagnoseCommand::checkGithubOauth
Return value
string|\Exception
1 call to DiagnoseCommand::checkGithubOauth()
- DiagnoseCommand::execute in vendor/
composer/ composer/ src/ Composer/ Command/ DiagnoseCommand.php - Executes the current command.
File
-
vendor/
composer/ composer/ src/ Composer/ Command/ DiagnoseCommand.php, line 438
Class
- DiagnoseCommand
- @author Jordi Boggiano <j.boggiano@seld.be>
Namespace
Composer\CommandCode
private function checkGithubOauth(string $domain, string $token) {
$result = $this->checkConnectivityAndComposerNetworkHttpEnablement();
if ($result !== true) {
return $result;
}
$this->getIO()
->setAuthentication($domain, $token, 'x-oauth-basic');
try {
$url = $domain === 'github.com' ? 'https://api.' . $domain . '/' : 'https://' . $domain . '/api/v3/';
$response = $this->httpDownloader
->get($url, [
'retry-auth-failure' => false,
]);
$expiration = $response->getHeader('github-authentication-token-expiration');
if ($expiration === null) {
return '<info>OK</> <comment>does not expire</>';
}
return '<info>OK</> <comment>expires on ' . $expiration . '</>';
} catch (\Exception $e) {
if ($e instanceof TransportException && $e->getCode() === 401) {
return '<comment>The oauth token for ' . $domain . ' seems invalid, run "composer config --global --unset github-oauth.' . $domain . '" to remove it</comment>';
}
return $e;
}
}