Skip to content

Commit

Permalink
Guzzle -> v6 [PLA-389] (#21)
Browse files Browse the repository at this point in the history
* 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 committed Dec 1, 2016
1 parent 8e987d7 commit ff1c4b5
Show file tree
Hide file tree
Showing 36 changed files with 1,180 additions and 1,360 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: php

php:
- 5.5
- 5.6
- 7.0
- hhvm
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

All Notable changes to `gigya-client` will be documented in this file

## 1.0 - 2016-11-28

### Changed
- Upgrade Guzzle from v5 to v6
- All Subscribers are now Guzzle Middleware
- Renamed `->addSubscriber` to `->addHandler`
- Renamed `->removeSubscriber` to `->removeHandler`

## 0.3 - 2016-04-02

### Added
- OAuth2 authentication

## 0.2 - 2015-10-20

### Changed
Expand Down
10 changes: 0 additions & 10 deletions Dockerfile

This file was deleted.

15 changes: 7 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
SHELL = /bin/sh

DOCKER ?= $(shell which docker)
DOCKER_REPOSITORY := graze/gigya-client
DOCKER_REPOSITORY := graze/php-alpine
VOLUME := /srv
VOLUME_MAP := -v $$(pwd):${VOLUME}
DOCKER_RUN_BASE := ${DOCKER} run --rm -t ${VOLUME_MAP} -w ${VOLUME}
DOCKER_RUN := ${DOCKER_RUN_BASE} ${DOCKER_REPOSITORY}:latest
DOCKER_RUN := ${DOCKER_RUN_BASE} ${DOCKER_REPOSITORY}:test

.PHONY: install composer clean help
.PHONY: test lint lint-fix test-unit test-integration test-matrix test-coverage test-coverage-html test-coverage-clover
Expand All @@ -16,14 +16,13 @@ DOCKER_RUN := ${DOCKER_RUN_BASE} ${DOCKER_REPOSITORY}:latest

install: ## Download the dependencies then build the image :rocket:.
make 'composer-install --optimize-autoloader --ignore-platform-reqs'
$(DOCKER) build --tag ${DOCKER_REPOSITORY}:latest .

composer-%: ## Run a composer command, `make "composer-<command> [...]"`.
${DOCKER} run -t --rm \
-v $$(pwd):/usr/src/app \
-v $$(pwd):/app \
-v ~/.composer:/root/composer \
-v ~/.ssh:/root/.ssh:ro \
graze/composer --ansi --no-interaction $* $(filter-out $@,$(MAKECMDGOALS))
composer/composer:alpine --ansi --no-interaction $* $(filter-out $@,$(MAKECMDGOALS))

clean: ## Clean up any images.
$(DOCKER) rmi ${DOCKER_REPOSITORY}:latest
Expand Down Expand Up @@ -54,13 +53,13 @@ test-performance: ## Run the performance testsuite.
$(DOCKER_RUN) vendor/bin/phpunit --colors=always --testsuite performance

test-coverage: ## Run all tests and output coverage to the console.
$(DOCKER_RUN) vendor/bin/phpunit --coverage-text --testsuite coverage
$(DOCKER_RUN) phpdbg7 -qrr vendor/bin/phpunit --coverage-text --testsuite coverage

test-coverage-html: ## Run all tests and output html results
$(DOCKER_RUN) vendor/bin/phpunit --coverage-html ./tests/report/html --testsuite coverage
$(DOCKER_RUN) phpdbg7 -qrr vendor/bin/phpunit --coverage-html ./tests/report/html --testsuite coverage

test-coverage-clover: ## Run all tests and output clover coverage to file.
$(DOCKER_RUN) vendor/bin/phpunit --coverage-clover=./tests/report/coverage.clover --testsuite coverage
$(DOCKER_RUN) phpdbg7 -qrr vendor/bin/phpunit --coverage-clover=./tests/report/coverage.clover --testsuite coverage


# Help
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ $account = $response->getData();
```php
$grant = new ManualGrant();
$gigya = new Gigya($key, $secret, $region, null, ['auth' => 'oauth2-custom']);
$gigya->addSubscriber(new OAuth2Subscriber($grant));
$gigya->addHandler(OAuth2Subscriber::middleware($grant));

$tokenResponse = $gigya->socialize()->getToken([
'grant_type' => 'code',
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
],
"require": {
"php": ">=5.5.0",
"guzzlehttp/guzzle": "^5.3",
"guzzlehttp/guzzle": "^6.2",
"illuminate/support": "^5.0",
"graze/standards": "^1.0"
},
"require-dev": {
"phpunit/phpunit" : "^4",
"phpunit/phpunit" : "^5",
"mockery/mockery": "^0.9.4",
"squizlabs/php_codesniffer": "^2.3"
},
Expand Down
99 changes: 0 additions & 99 deletions src/Auth/CredentialsAuth.php

This file was deleted.

116 changes: 116 additions & 0 deletions src/Auth/CredentialsAuthMiddleware.php
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);
};
}
}
Loading

0 comments on commit ff1c4b5

Please sign in to comment.