Skip to content

Commit ececd21

Browse files
authored
Merge pull request #32 from kamermans/stream_for-deprecation
Avoid deprecations, update test platform
2 parents 840fde5 + 9a1d256 commit ececd21

13 files changed

+39
-44
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: php
22

3-
dist: trusty
3+
dist: bionic
44

55
php:
66
- 5.4

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Guzzle OAuth 2.0 Subscriber
22

3-
> [![Build Status](https://travis-ci.org/kamermans/guzzle-oauth2-subscriber.svg?branch=master)](https://travis-ci.org/kamermans/guzzle-oauth2-subscriber)
43
> Tested with Guzzle 4, 5, 6, 7 and PHP 5.4, 5.5, 5.6, 7.0, 7.1, 7.2, 7.3 and 7.4.
54
65
This is an OAuth 2.0 client for Guzzle which aims to be 100% compatible with Guzzle 4, 5, 6, 7 and all future versions within a single package.

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "kamermans/guzzle-oauth2-subscriber",
3-
"description": "OAuth 2.0 client for Guzzle 4, 5 and 6+",
3+
"description": "OAuth 2.0 client for Guzzle 4, 5, 6 and 7+",
44
"keywords": ["oauth", "guzzle"],
55
"license": "MIT",
66
"authors": [

guzzle_environments/run_tests_docker.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function run_tests()
1414
echo "# Running tests against Guzzle $GUZZLE_VER"
1515
echo "###############################################"
1616

17-
docker run -ti --rm \
17+
docker run --rm \
1818
-v $DIR/../:/test \
1919
--workdir=/test/guzzle_environments/$GUZZLE_VER \
2020
--entrypoint=/bin/sh \

src/GrantType/AuthorizationCode.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function getRawData(SignerInterface $clientCredentialsSigner, $refreshTok
7171
}
7272

7373
/**
74-
* @return PostBody
74+
* @return PostBody|\Psr\Http\Message\StreamInterface
7575
*/
7676
protected function getPostBody()
7777
{
@@ -89,7 +89,7 @@ protected function getPostBody()
8989
$data['redirect_uri'] = $this->config['redirect_uri'];
9090
}
9191

92-
return \GuzzleHttp\Psr7\stream_for(http_build_query($data, '', '&'));
92+
return Helper::streamFor(http_build_query($data, '', '&'));
9393
}
9494

9595
$postBody = new PostBody();

src/GrantType/ClientCredentials.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function getRawData(SignerInterface $clientCredentialsSigner, $refreshTok
7373
}
7474

7575
/**
76-
* @return PostBody
76+
* @return PostBody|\Psr\Http\Message\StreamInterface
7777
*/
7878
protected function getPostBody()
7979
{
@@ -90,7 +90,7 @@ protected function getPostBody()
9090
$data['audience'] = $this->config['audience'];
9191
}
9292

93-
return \GuzzleHttp\Psr7\stream_for(http_build_query($data, '', '&'));
93+
return Helper::streamFor(http_build_query($data, '', '&'));
9494
}
9595

9696
$postBody = new PostBody();

src/GrantType/PasswordCredentials.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ public function getRawData(SignerInterface $clientCredentialsSigner, $refreshTok
7171
}
7272

7373
/**
74-
* @return PostBody
75-
*/
74+
* @return PostBody|\Psr\Http\Message\StreamInterface
75+
*/
7676
protected function getPostBody()
7777
{
7878
if (Helper::guzzleIs('>=', '6')) {
@@ -86,7 +86,7 @@ protected function getPostBody()
8686
$data['scope'] = $this->config['scope'];
8787
}
8888

89-
return \GuzzleHttp\Psr7\stream_for(http_build_query($data, '', '&'));
89+
return Helper::streamFor(http_build_query($data, '', '&'));
9090
}
9191

9292
$postBody = new PostBody();

src/GrantType/RefreshToken.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ public function getRawData(SignerInterface $clientCredentialsSigner, $refreshTok
7070
}
7171

7272
/**
73-
* @return PostBody
74-
*/
73+
* @return PostBody|\Psr\Http\Message\StreamInterface
74+
*/
7575
protected function getPostBody($refreshToken)
7676
{
7777
if (Helper::guzzleIs('>=', '6')) {
@@ -86,7 +86,7 @@ protected function getPostBody($refreshToken)
8686
$data['scope'] = $this->config['scope'];
8787
}
8888

89-
return \GuzzleHttp\Psr7\stream_for(http_build_query($data, '', '&'));
89+
return Helper::streamFor(http_build_query($data, '', '&'));
9090
}
9191

9292
$postBody = new PostBody();

src/GrantType/Specific/GithubApplication.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ protected function getPostBody()
127127

128128
$postBody = json_encode($postBody);
129129

130-
return Helper::guzzleIs('<', 6)? Stream::factory($postBody): \GuzzleHttp\Psr7\stream_for($postBody);
130+
return Helper::guzzleIs('<', 6)? Stream::factory($postBody): Helper::streamFor($postBody);
131131
}
132132

133133
/**

src/Signer/ClientCredentials/PostFormData.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function sign($request, $clientId, $clientSecret)
2727
$data[$this->clientIdField] = $clientId;
2828
$data[$this->clientSecretField] = $clientSecret;
2929

30-
$body_stream = \GuzzleHttp\Psr7\stream_for(http_build_query($data, '', '&'));
30+
$body_stream = Helper::streamFor(http_build_query($data, '', '&'));
3131
return $request->withBody($body_stream);
3232
}
3333

src/Utils/Helper.php

+23
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,29 @@
66

77
class Helper
88
{
9+
/**
10+
* Create a new stream based on the input type.
11+
*
12+
* Options is an associative array that can contain the following keys:
13+
* - metadata: Array of custom metadata.
14+
* - size: Size of the stream.
15+
*
16+
* @param resource|string|null|int|float|bool|StreamInterface|callable|\Iterator $resource Entity body data
17+
* @param array $options Additional options
18+
*
19+
* @return StreamInterface
20+
* @throws \InvalidArgumentException if the $resource arg is not valid.
21+
*/
22+
public static function streamFor($resource = '', array $options = [])
23+
{
24+
// stream_for was used until GuzzleHttp\Psr7 v1.7.0
25+
if (function_exists('GuzzleHttp\Psr7\stream_for')) {
26+
return \GuzzleHttp\Psr7\stream_for($resource, $options);
27+
}
28+
29+
return \GuzzleHttp\Psr7\Utils::streamFor($resource, $options);
30+
}
31+
932
public static function guzzleIs($operator, $version, $guzzle_version=null)
1033
{
1134
if ($guzzle_version === null) {

tests/BaseTestCase.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected function parseQueryString($query_string)
6767
protected function setPostBody($request, array $data=[])
6868
{
6969
if (Helper::guzzleIs('>=', 6)) {
70-
return $request->withBody(\GuzzleHttp\Psr7\stream_for(http_build_query($data, '', '&')));
70+
return $request->withBody(Helper::streamFor(http_build_query($data, '', '&')));
7171
}
7272

7373
$request->setBody(new PostBody($data));

tests/OAuth2MiddlewareTest.php

-27
Original file line numberDiff line numberDiff line change
@@ -568,31 +568,4 @@ public function testOnErrorDoesNotLoop()
568568
$this->assertSame(401, $container[0]['response']->getStatusCode());
569569
$this->assertSame(401, $container[1]['response']->getStatusCode());
570570
}
571-
572-
public function __DISABLED__testOnErrorDoesNotLoop()
573-
{
574-
// Setup Grant Type
575-
$grant = $this->getMockBuilder('\kamermans\OAuth2\GrantType\ClientCredentials')
576-
->setMethods(['getRawData'])
577-
->disableOriginalConstructor()
578-
->getMock();
579-
580-
$grant->expects($this->exactly(0))
581-
->method('getRawData');
582-
583-
// Setup OAuth2Middleware
584-
$sub = new OAuth2Middleware($grant);
585-
586-
$client = new Client();
587-
$request = new Request('GET', '/', [], null, ['auth' => 'oauth']);
588-
// This header keeps the subscriber from trying to reauth a reauth request (infinte loop)
589-
$request->setHeader('X-Guzzle-Retry', 1);
590-
$response = new Response(401);
591-
$transaction = $this->getTransaction($client, $request);
592-
$except = new RequestException('foo', $request, $response);
593-
$event = new ErrorEvent($transaction, $except);
594-
595-
// Force an onError event, which triggers the signer and grant data processor
596-
$sub->onError($event);
597-
}
598571
}

0 commit comments

Comments
 (0)