Skip to content

Commit

Permalink
Release 2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dm committed May 20, 2016
1 parent f7ed191 commit ec21b54
Show file tree
Hide file tree
Showing 22 changed files with 197 additions and 188 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ sudo: false

php:
- 5.6
- 5.5
- 5.4
- 7.0
- hhvm

Expand Down
64 changes: 34 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
guzzle-oauth2-plugin
====================
![logo](http://www.sainsburys.co.uk/homepage/images/sainsburys.png)

Provides an OAuth2 plugin (subscriber) for [Guzzle](http://guzzlephp.org/).
Sainsbury's guzzle-oauth2-plugin
================================

[![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)
Provides an OAuth2 plugin (middleware) for [Guzzle](http://guzzlephp.org/).

Version 2.x (on the `master` branch) is intended for Guzzle 5:
[![Build Status](https://travis-ci.org/Sainsburys/guzzle-oauth2-plugin.svg?branch=release%2F2.0)](https://travis-ci.org/Sainsburys/guzzle-oauth2-plugin)
[![Code Coverage](https://scrutinizer-ci.com/g/Sainsburys/guzzle-oauth2-plugin/badges/coverage.png?b=release%2F2.0)](https://scrutinizer-ci.com/g/Sainsburys/guzzle-oauth2-plugin/?branch=release%2F2.0)

Version 3.x (on the `master` branch) is intended for Guzzle 6:
```json
"commerceguys/guzzle-oauth2-plugin": "~2.0"
"sainsburys/guzzle-oauth2-plugin": "~3.0"
```

Guzzle 3 compatibility continues in the [`1.0`](https://github.com/commerceguys/guzzle-oauth2-plugin/tree/1.0) branch:
Version 2.x (on the `release/2.0` branch) is intended for Guzzle 5:
```json
"commerceguys/guzzle-oauth2-plugin": "~1.0"
"sainsburys/guzzle-oauth2-plugin": "~2.0"
```

Version 1.x (on the `release/1.0` branch) is intended for Guzzle 3 [Unmaintained]:
```json
"sainsburys/guzzle-oauth2-plugin": "~1.0"
```

## Features
Expand All @@ -29,39 +36,36 @@ First make sure you have all the dependencies in place by running `composer inst

## Example
```php
use GuzzleHttp\Client;
use CommerceGuys\Guzzle\Oauth2\GrantType\RefreshToken;
use CommerceGuys\Guzzle\Oauth2\GrantType\PasswordCredentials;
use CommerceGuys\Guzzle\Oauth2\Oauth2Subscriber;
use GuzzleHttp\HandlerStack;
use Sainsburys\Guzzle\Oauth2\GrantType\RefreshToken;
use Sainsburys\Guzzle\Oauth2\GrantType\PasswordCredentials;
use Sainsburys\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::CONFIG_USERNAME => '[email protected]',
PasswordCredentials::CONFIG_PASSWORD => 'test password',
PasswordCredentials::CONFIG_CLIENT_ID => 'test-client',
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.

```
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "commerceguys/guzzle-oauth2-plugin",
"name": "sainsburys/guzzle-oauth2-plugin",
"description": "An OAuth2 plugin (subscriber) for Guzzle",
"license": "MIT",
"require": {
Expand All @@ -8,15 +8,15 @@
},
"autoload": {
"psr-4": {
"CommerceGuys\\Guzzle\\Oauth2\\": "src"
"Sainsburys\\Guzzle\\Oauth2\\": "src"
}
},
"require-dev": {
"phpunit/phpunit": "~4.5"
},
"autoload-dev": {
"psr-4": {
"CommerceGuys\\Guzzle\\Oauth2\\Tests\\": "tests"
"Sainsburys\\Guzzle\\Oauth2\\Tests\\": "tests"
}
},
"authors": [
Expand All @@ -28,6 +28,9 @@
},
{
"name": "Patrick Dawkins"
},
{
"name": "Daniel Macedo"
}
],
"config": {
Expand Down
Loading

0 comments on commit ec21b54

Please sign in to comment.