Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion .scrutinizer.yml
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.6.16
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'
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
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
The MIT License (MIT)

Copyright (c) 2013 Bojan Zivanovic
Copyright (c) 2016 Daniel Macedo, Sainsbury's Supermarkets Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
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=master)](https://travis-ci.org/Sainsburys/guzzle-oauth2-plugin)
[![Code Coverage](https://scrutinizer-ci.com/g/Sainsburys/guzzle-oauth2-plugin/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/Sainsburys/guzzle-oauth2-plugin/?branch=master)

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 5 [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' => 'test@example.com',
'password' => 'test password',
'client_id' => 'test-client',
PasswordCredentials::CONFIG_USERNAME => 'test@example.com',
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.

```
13 changes: 8 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"name": "commerceguys/guzzle-oauth2-plugin",
"name": "sainsburys/guzzle-oauth2-plugin",
"description": "An OAuth2 plugin (subscriber) for Guzzle",
"license": "MIT",
"require": {
"guzzlehttp/guzzle": "~5.0",
"firebase/php-jwt": "~2.0"
"guzzlehttp/guzzle": "~6.0",
"firebase/php-jwt": "~3.0"
},
"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