-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* upgrade to guzzle v6 instead of v5 * remove support for php5.5, because * fix some code styling stuff * some comprehisilbity fixes * code readability * update build image to use php7-phpdbg, 100% coverage * actually add the query parameters into the url
- Loading branch information
Harry Bragg
authored
Dec 1, 2016
1 parent
8e987d7
commit ff1c4b5
Showing
36 changed files
with
1,180 additions
and
1,360 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
language: php | ||
|
||
php: | ||
- 5.5 | ||
- 5.6 | ||
- 7.0 | ||
- hhvm | ||
|
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 was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,116 @@ | ||
<?php | ||
/** | ||
* This file is part of graze/gigya-client | ||
* | ||
* Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @license https://github.com/graze/gigya-client/blob/master/LICENSE.md | ||
* @link https://github.com/graze/gigya-client | ||
*/ | ||
|
||
namespace Graze\Gigya\Auth; | ||
|
||
use Closure; | ||
use GuzzleHttp\Psr7\Uri; | ||
use Psr\Http\Message\RequestInterface; | ||
use Psr\Http\Message\ResponseInterface as GuzzleResponseInterface; | ||
|
||
class CredentialsAuthMiddleware | ||
{ | ||
const AUTH_NAME = 'credentials'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $apiKey; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $secret; | ||
|
||
/** | ||
* @var null|string | ||
*/ | ||
private $userKey; | ||
/** | ||
* @var callable | ||
*/ | ||
private $nextHandler; | ||
|
||
/** | ||
* @param callable $nextHandler | ||
* @param string $apiKey | ||
* @param string $secret | ||
* @param string|null $userKey | ||
*/ | ||
public function __construct(callable $nextHandler, $apiKey, $secret, $userKey = null) | ||
{ | ||
$this->nextHandler = $nextHandler; | ||
$this->apiKey = $apiKey; | ||
$this->secret = $secret; | ||
$this->userKey = $userKey; | ||
} | ||
|
||
/** | ||
* Inject credentials information into the query parameters | ||
* | ||
* @param RequestInterface $request | ||
* @param array $options | ||
* | ||
* @return GuzzleResponseInterface | ||
*/ | ||
public function __invoke(RequestInterface $request, array $options) | ||
{ | ||
if ($request->getUri()->getScheme() == 'https' && $options['auth'] == static::AUTH_NAME) { | ||
$uri = Uri::withQueryValue($request->getUri(), 'client_id', $this->userKey ?: $this->apiKey); | ||
$uri = Uri::withQueryValue($uri, 'client_secret', $this->secret); | ||
$request = $request->withUri($uri); | ||
} | ||
$fn = $this->nextHandler; | ||
return $fn($request, $options); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getApiKey() | ||
{ | ||
return $this->apiKey; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getSecret() | ||
{ | ||
return $this->secret; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getUserKey() | ||
{ | ||
return $this->userKey; | ||
} | ||
|
||
/** | ||
* Return a middleware handler function for this Authentication | ||
* | ||
* @param string $apiKey | ||
* @param string $secret | ||
* @param string|null $userKey | ||
* | ||
* @return Closure | ||
*/ | ||
public static function middleware($apiKey, $secret, $userKey = null) | ||
{ | ||
return function (callable $handler) use ($apiKey, $secret, $userKey) { | ||
return new static($handler, $apiKey, $secret, $userKey); | ||
}; | ||
} | ||
} |
Oops, something went wrong.