-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Commit
GitHub's new fine-grained tokens have a cumpulsory expiration date, and their classic tokens also support an expiration date. https://github.blog/changelog/2021-07-26-expiration-options-for-personal-access-tokens/ This improves the `composer diagnose` command to display the expiration date and time if it is provided by the response headers (via `GitHub-Authentication-Token-Expiration`).
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -327,10 +327,20 @@ private function checkGithubOauth(string $domain, string $token) | |
try { | ||
$url = $domain === 'github.com' ? 'https://api.'.$domain.'/' : 'https://'.$domain.'/api/v3/'; | ||
|
||
$this->httpDownloader->get($url, [ | ||
$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</>'; | ||
} | ||
|
||
if (\DateTime::createFromFormat('Y-m-d h:i:s O', $expiration) !== false) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
stof
Contributor
|
||
return '<info>OK</> <comment>expires on '. $expiration .'</>'; | ||
This comment has been minimized.
Sorry, something went wrong.
ktomk
Contributor
|
||
} | ||
|
||
return true; | ||
} catch (\Exception $e) { | ||
if ($e instanceof TransportException && $e->getCode() === 401) { | ||
|
In PHP 8 something, createFromFormat throws ValueError if
$expriration
contains a null byte. From my tests I'm pretty confident to say thatstrtotime()
does suffice (same!== false
test), might be some upcoming PHP 8, in any case strtotime() is less error prone:https://3v4l.org/TbVIDhttps://3v4l.org/fH0sA (2xedit: better example)