-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from jwage/github-auth
Add support for authentication when making requests to GitHub API.
- Loading branch information
Showing
11 changed files
with
302 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ChangelogGenerator; | ||
|
||
interface GitHubCredentials | ||
{ | ||
public function getAuthorizationHeader() : string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ChangelogGenerator; | ||
|
||
use function sprintf; | ||
|
||
final class GitHubOAuthToken implements GitHubCredentials | ||
{ | ||
/** @var string */ | ||
private $oAuthToken; | ||
|
||
public function __construct(string $oAuthToken) | ||
{ | ||
$this->oAuthToken = $oAuthToken; | ||
} | ||
|
||
public function getAuthorizationHeader() : string | ||
{ | ||
return sprintf('token %s', $this->oAuthToken); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ChangelogGenerator; | ||
|
||
use function base64_encode; | ||
use function sprintf; | ||
|
||
final class GitHubUsernamePassword implements GitHubCredentials | ||
{ | ||
/** @var string */ | ||
private $username; | ||
|
||
/** @var string */ | ||
private $passwordOrToken; | ||
|
||
public function __construct(string $username, string $passwordOrToken) | ||
{ | ||
$this->username = $username; | ||
$this->passwordOrToken = $passwordOrToken; | ||
} | ||
|
||
public function getAuthorizationHeader() : string | ||
{ | ||
return sprintf('Basic %s', base64_encode(sprintf('%s:%s', $this->username, $this->passwordOrToken))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ChangelogGenerator\Tests; | ||
|
||
use ChangelogGenerator\GitHubOAuthToken; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class GitHubOAuthTokenTest extends TestCase | ||
{ | ||
public function testGetHttpBasicAuthorization() : void | ||
{ | ||
self::assertSame( | ||
'token oauthtoken', | ||
(new GitHubOAuthToken('oauthtoken'))->getAuthorizationHeader() | ||
); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
tests/ChangelogGenerator/Tests/GitHubUsernamePasswordTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ChangelogGenerator\Tests; | ||
|
||
use ChangelogGenerator\GitHubUsernamePassword; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class GitHubUsernamePasswordTest extends TestCase | ||
{ | ||
public function testGetHttpBasicAuthorization() : void | ||
{ | ||
self::assertSame( | ||
'Basic dXNlcm5hbWU6cGFzc3dvcmQ=', | ||
(new GitHubUsernamePassword('username', 'password'))->getAuthorizationHeader() | ||
); | ||
} | ||
} |
Oops, something went wrong.