-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update to guzzle 6 #29
base: master
Are you sure you want to change the base?
Changes from all commits
dd8ae23
16e3b1f
48d7cf7
8643a72
8371061
d83fa0c
8b7e96a
43919e4
530cf8d
815352d
5bc155b
635ce6d
8576eeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,24 @@ | ||
build_failure_conditions: | ||
- 'issues.label("coding-style").new.exists' | ||
- 'issues.severity(>= MAJOR).new.exists' | ||
|
||
tools: | ||
external_code_coverage: true | ||
external_code_coverage: false | ||
php_code_sniffer: | ||
config: { standard: 'PSR2' } | ||
|
||
build: | ||
environment: | ||
php: | ||
version: 5.5.12 | ||
ini: | ||
display_errors: true | ||
date.timezone: Europe/London | ||
memory_limit: 2G | ||
tests: | ||
override: | ||
- | ||
command: 'bin/phpunit --coverage-clover=coverage.clover' | ||
coverage: | ||
file: 'coverage.clover' | ||
format: 'php-clover' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ sudo: false | |
php: | ||
- 5.6 | ||
- 5.5 | ||
- 5.4 | ||
- 7.0 | ||
- hhvm | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,12 @@ | ||
guzzle-oauth2-plugin | ||
==================== | ||
|
||
Provides an OAuth2 plugin (subscriber) for [Guzzle](http://guzzlephp.org/). | ||
Provides an OAuth2 plugin (middleware) for [Guzzle](http://guzzlephp.org/). | ||
|
||
[![Build Status](https://travis-ci.org/commerceguys/guzzle-oauth2-plugin.svg)](https://travis-ci.org/commerceguys/guzzle-oauth2-plugin) | ||
[![Code Coverage](https://scrutinizer-ci.com/g/commerceguys/guzzle-oauth2-plugin/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/commerceguys/guzzle-oauth2-plugin/?branch=master) | ||
|
||
Version 2.x (on the `master` branch) is intended for Guzzle 5: | ||
```json | ||
"commerceguys/guzzle-oauth2-plugin": "~2.0" | ||
``` | ||
|
||
Guzzle 3 compatibility continues in the [`1.0`](https://github.com/commerceguys/guzzle-oauth2-plugin/tree/1.0) branch: | ||
```json | ||
"commerceguys/guzzle-oauth2-plugin": "~1.0" | ||
``` | ||
This version is intended for Guzzle 6: | ||
|
||
## Features | ||
|
||
|
@@ -32,36 +24,33 @@ First make sure you have all the dependencies in place by running `composer inst | |
use GuzzleHttp\Client; | ||
use CommerceGuys\Guzzle\Oauth2\GrantType\RefreshToken; | ||
use CommerceGuys\Guzzle\Oauth2\GrantType\PasswordCredentials; | ||
use CommerceGuys\Guzzle\Oauth2\Oauth2Subscriber; | ||
use CommerceGuys\Guzzle\Oauth2\OAuthMiddleware; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use CommerceGuys\Guzzle\Oauth2\Middleware\OAuthMiddleware; |
||
|
||
$base_url = 'https://example.com'; | ||
$base_uri = 'https://example.com'; | ||
|
||
$oauth2Client = new Client(['base_url' => $base_url]); | ||
$handlerStack = HandlerStack::create(); | ||
$client = new Client(['handler'=> $handlerStack, 'base_uri' => $base_uri, 'auth' => 'oauth2']); | ||
|
||
$config = [ | ||
'username' => '[email protected]', | ||
'password' => 'test password', | ||
'client_id' => 'test-client', | ||
PasswordCredentials::USERNAME => '[email protected]', | ||
PasswordCredentials::PASSWORD => 'test password', | ||
PasswordCredentials::CLIENT_ID => 'test-client', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PasswordCredentials::CONFIG_USERNAME => '[email protected]', |
||
PasswordCredentials::CONFIG_TOKEN_URL => '/oauth/token', | ||
'scope' => 'administration', | ||
]; | ||
|
||
$token = new PasswordCredentials($oauth2Client, $config); | ||
$refreshToken = new RefreshToken($oauth2Client, $config); | ||
|
||
$oauth2 = new Oauth2Subscriber($token, $refreshToken); | ||
$token = new PasswordCredentials($client, $config); | ||
$refreshToken = new RefreshToken($client, $config); | ||
$middleware = new OAuthMiddleware($client, $token, $refreshToken); | ||
|
||
$client = new Client([ | ||
'defaults' => [ | ||
'auth' => 'oauth2', | ||
'subscribers' => [$oauth2], | ||
], | ||
]); | ||
$handlerStack->push($middleware->onBefore()); | ||
$handlerStack->push($middleware->onFailure(5)); | ||
|
||
$response = $client->get('https://example.com/api/user/me'); | ||
$response = $client->get('/api/user/me'); | ||
|
||
print_r($response->json()); | ||
|
||
// Use $oauth2->getAccessToken(); and $oauth2->getRefreshToken() to get tokens | ||
// Use $middleware->getAccessToken(); and $middleware->getRefreshToken() to get tokens | ||
// that can be persisted for subsequent requests. | ||
|
||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use GuzzleHttp\HandlerStack;