Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f4ee4a7
Showing
57 changed files
with
3,228 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
vendor/ | ||
*.swp | ||
.php-cs.cache | ||
guzzle_environments/*/vendor/ | ||
guzzle_environments/*/composer.lock | ||
composer.lock | ||
examples/ |
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,18 @@ | ||
<?php | ||
|
||
$finder = PhpCsFixer\Finder::create() | ||
->in(__DIR__) | ||
->exclude("vendor") | ||
->exclude("guzzle_environments") | ||
; | ||
|
||
return PhpCsFixer\Config::create() | ||
->setRules(array( | ||
'@PSR2' => true, | ||
'array_syntax' => ['syntax' => 'short'], | ||
'no_unused_imports' => true, | ||
'blank_line_after_opening_tag' => true, | ||
'blank_line_after_namespace' => true, | ||
)) | ||
->setFinder($finder) | ||
; |
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 @@ | ||
======================= | ||
Guzzle OAuth 2.0 Subscriber | ||
======================= | ||
|
||
This is an OAuth 2.0 client for Guzzle which aims to be 100% compatible with Guzzle 4, 5, 6 and all future versions within a single package. | ||
Although I love Guzzle, its interfaces keep changing, causing massive breaking changes every 12 months or so, so I have created this package | ||
to help reduce the dependency hell that most third-party Guzzle dependencies bring with them. I wrote the official Guzzle OAuth 2.0 plugin | ||
which is still on the `oauth2` branch, [over at the official Guzzle repo](https://github.com/guzzle/oauth-subscriber/tree/oauth2), but I | ||
see that they have dropped support for Guzzle < v6 on `master`, which prompted me to split this back off to a separate package. | ||
|
||
Installing | ||
========== | ||
|
||
This project can be installed using Composer. Add the following to your | ||
composer.json: | ||
|
||
```javascript | ||
{ | ||
"require": { | ||
"kamermans/guzzle-oauth2-subscriber": "~1.0" | ||
} | ||
} | ||
``` |
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,30 @@ | ||
{ | ||
"name": "kamermans/guzzle-oauth-subscriber", | ||
"description": "OAuth 2.0 client for Guzzle 4, 5 and 6+", | ||
"keywords": ["oauth", "guzzle"], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Steve Kamerman", | ||
"email": "stevekamerman@gmail.com" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.4.0", | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"kamermans\\OAuth2\\": "src/OAuth2" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"kamermans\\OAuth2\\Tests\\": "tests/OAuth2" | ||
} | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "0.1-dev" | ||
} | ||
} | ||
} |
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,24 @@ | ||
{ | ||
"name": "kamermans/unit-tests", | ||
"authors": [ | ||
{ | ||
"name": "Steve Kamerman", | ||
"email": "stevekamerman@gmail.com" | ||
} | ||
], | ||
"require-dev": { | ||
"guzzlehttp/guzzle": "~4", | ||
"phpunit/phpunit": "~4.0", | ||
"doctrine/cache": "~1.5" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"kamermans\\OAuth2\\": "../../src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"kamermans\\OAuth2\\Tests\\": "../../tests" | ||
} | ||
} | ||
} |
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,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="./vendor/autoload.php" | ||
colors="true"> | ||
<testsuites> | ||
<testsuite name="All Tests"> | ||
<directory>../../tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix="Test.php">.</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
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,24 @@ | ||
{ | ||
"name": "kamermans/unit-tests", | ||
"authors": [ | ||
{ | ||
"name": "Steve Kamerman", | ||
"email": "stevekamerman@gmail.com" | ||
} | ||
], | ||
"require-dev": { | ||
"guzzlehttp/guzzle": "~5", | ||
"phpunit/phpunit": "~4.0", | ||
"doctrine/cache": "~1.5" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"kamermans\\OAuth2\\": "../../src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"kamermans\\OAuth2\\Tests\\": "../../tests" | ||
} | ||
} | ||
} |
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,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="./vendor/autoload.php" | ||
colors="true"> | ||
<testsuites> | ||
<testsuite name="All Tests"> | ||
<directory>../../tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix="Test.php">.</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
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,24 @@ | ||
{ | ||
"name": "kamermans/unit-tests", | ||
"authors": [ | ||
{ | ||
"name": "Steve Kamerman", | ||
"email": "stevekamerman@gmail.com" | ||
} | ||
], | ||
"require-dev": { | ||
"guzzlehttp/guzzle": "~6", | ||
"phpunit/phpunit": "~4.0", | ||
"doctrine/cache": "~1.5" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"kamermans\\OAuth2\\": "../../src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"kamermans\\OAuth2\\Tests\\": "../../tests" | ||
} | ||
} | ||
} |
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,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="./vendor/autoload.php" | ||
colors="true"> | ||
<testsuites> | ||
<testsuite name="All Tests"> | ||
<directory>../../tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix="Test.php">.</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
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,7 @@ | ||
<?php | ||
|
||
namespace kamermans\OAuth2\Exception; | ||
|
||
class AccessTokenRequestException extends ReauthorizationRequestException | ||
{ | ||
} |
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,7 @@ | ||
<?php | ||
|
||
namespace kamermans\OAuth2\Exception; | ||
|
||
class OAuth2Exception extends \RuntimeException | ||
{ | ||
} |
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,7 @@ | ||
<?php | ||
|
||
namespace kamermans\OAuth2\Exception; | ||
|
||
class ReauthorizationException extends OAuth2Exception | ||
{ | ||
} |
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 | ||
|
||
namespace kamermans\OAuth2\Exception; | ||
|
||
use GuzzleHttp\Exception\TransferException; | ||
|
||
class ReauthorizationRequestException extends ReauthorizationException | ||
{ | ||
public function __construct($message, TransferException $guzzleException) | ||
{ | ||
parent::__construct($message, 0, $guzzleException); | ||
} | ||
|
||
/** | ||
* Get the Guzzle Exception that was thrown while trying to reauthorize. | ||
* | ||
* @return GuzzleHttp\Exception\TransferException | ||
*/ | ||
public function getGuzzleException() | ||
{ | ||
return $this->getPrevious(); | ||
} | ||
} |
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,93 @@ | ||
<?php | ||
|
||
namespace kamermans\OAuth2\GrantType; | ||
|
||
use GuzzleHttp\Post\PostBody; | ||
use GuzzleHttp\ClientInterface; | ||
use kamermans\OAuth2\Utils\Helper; | ||
use kamermans\OAuth2\Utils\Collection; | ||
use kamermans\OAuth2\Signer\ClientCredentials\SignerInterface; | ||
|
||
/** | ||
* Authorization code grant type. | ||
* | ||
* @link http://tools.ietf.org/html/rfc6749#section-4.1 | ||
*/ | ||
class AuthorizationCode implements GrantTypeInterface | ||
{ | ||
/** | ||
* The token endpoint client. | ||
* | ||
* @var ClientInterface | ||
*/ | ||
private $client; | ||
|
||
/** | ||
* Configuration settings. | ||
* | ||
* @var Collection | ||
*/ | ||
private $config; | ||
|
||
public function __construct(ClientInterface $client, array $config) | ||
{ | ||
$this->client = $client; | ||
$this->config = Collection::fromConfig($config, | ||
// Defaults | ||
[ | ||
'client_secret' => '', | ||
'scope' => '', | ||
'redirect_uri' => '', | ||
], | ||
// Required | ||
[ | ||
'client_id', | ||
'code', | ||
] | ||
); | ||
} | ||
|
||
public function getRawData(SignerInterface $clientCredentialsSigner, $refreshToken = null) | ||
{ | ||
if (Helper::guzzleIs('>=', 6)) { | ||
$request = new \GuzzleHttp\Psr7\Request('POST', null, [ | ||
'body' => $this->getPostBody(), | ||
]); | ||
} else { | ||
$request = $this->client->createRequest('POST', null); | ||
$request->setBody($this->getPostBody()); | ||
} | ||
|
||
$request = $clientCredentialsSigner->sign( | ||
$request, | ||
$this->config['client_id'], | ||
$this->config['client_secret'] | ||
); | ||
|
||
$response = $this->client->send($request); | ||
|
||
return $response->json(); | ||
} | ||
|
||
/** | ||
* @return PostBody | ||
*/ | ||
protected function getPostBody() | ||
{ | ||
$postBody = new PostBody(); | ||
$postBody->replaceFields([ | ||
'grant_type' => 'authorization_code', | ||
'code' => $this->config['code'], | ||
]); | ||
|
||
if ($this->config['scope']) { | ||
$postBody->setField('scope', $this->config['scope']); | ||
} | ||
|
||
if ($this->config['redirect_uri']) { | ||
$postBody->setField('redirect_uri', $this->config['redirect_uri']); | ||
} | ||
|
||
return $postBody; | ||
} | ||
} |
Oops, something went wrong.