Skip to content

Commit 988b39c

Browse files
bug #842 Pass GitHub access token when accessing raw.githubusercontent.com in case of private recipes (aivus)
This PR was merged into the 1.x branch. Discussion ---------- Pass GitHub access token when accessing raw.githubusercontent.com in case of private recipes I'm checking how to use private symfony recipes and found that `symfony/flex` is not using GH access token when accessing `raw.githubcontent.com`. For a public repositories it's not a case, but for private repositories it's not possible to access the recipe template url from `raw.githubcontent.com` without using access token. Adding access token for requests to `api.github.com` is [covered by Composer](https://github.com/composer/composer/blob/f5ffedfe60b5b0043c368b91e656288517aad0d9/src/Composer/Util/AuthHelper.php#L210-L215), but it doesn't cover downloading files from `raw.githubcontent.com`. This PR introduces logic for adding token for requests to `raw.githubcontent.com` in the [similar way as composer does](https://github.com/composer/composer/blob/f5ffedfe60b5b0043c368b91e656288517aad0d9/src/Composer/Util/AuthHelper.php#L210-L215) for `api.github.com`. Limitations: * Current implementation adds the token (if it presents) to ALL requests to the `raw.githubusercontent.com`, but I don't think that it's a big issue actually. Commits ------- d7dd781 Pass GitHub access token when accessing raw.githubusercontent.com
2 parents 787e2e3 + d7dd781 commit 988b39c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/Downloader.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,11 @@ private function get(array $urls, bool $isRecipe = false, int $try = 3): array
338338

339339
if (preg_match('{^https?://api\.github\.com/}', $url)) {
340340
$headers[] = 'Accept: application/vnd.github.v3.raw';
341+
} elseif (preg_match('{^https?://raw\.githubusercontent\.com/}', $url) && $this->io->hasAuthentication('github.com')) {
342+
$auth = $this->io->getAuthentication('github.com');
343+
if ('x-oauth-basic' === $auth['password']) {
344+
$headers[] = 'Authorization: token '.$auth['username'];
345+
}
341346
} elseif ($this->legacyEndpoint) {
342347
$headers[] = 'Package-Session: '.$this->sess;
343348
}

0 commit comments

Comments
 (0)