Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use authorization: token header for Github authentication #211

Merged
merged 2 commits into from
Feb 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected function setupAuthentication(IO\IOInterface $io, $useRedirector, array

// is github
if (in_array($authKey, $githubDomains) && 'x-oauth-basic' === $auth['password']) {
$this->addParam('access_token', $auth['username']);
$this->addHeader('authorization', 'token ' . $auth['username']);
$this->user = $this->pass = null;
return;
}
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/CopyRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,15 @@ public function testGitHubRedirector()

// user:pass -> query
$req = new CopyRequest($example, $tmpfile, false, $this->iop->reveal(), $this->configp->reveal());
$this->assertEquals("$example&access_token=at", $req->getURL());
$this->assertEquals($example, $req->getURL());
$opts = $req->getCurlOptions();
$this->assertContains('Authorization: token at', $opts[CURLOPT_HTTPHEADER]);

// api.github.com -> codeload.github.com
$req = new CopyRequest($example, $tmpfile, true, $this->iop->reveal(), $this->configp->reveal());
$this->assertEquals('https://codeload.github.com/vendor/name/legacy.zip/aaaa?a=b&access_token=at', $req->getURL());
$this->assertEquals('https://codeload.github.com/vendor/name/legacy.zip/aaaa?a=b', $req->getURL());
$opts = $req->getCurlOptions();
$this->assertContains('Authorization: token at', $opts[CURLOPT_HTTPHEADER]);
}

public function testGitLab()
Expand Down