2017 © Pedro Peláez
 

library oauth2-client-middleware

OAuth2 PSR7 middleware for league/oauth2-client

image

somoza/oauth2-client-middleware

OAuth2 PSR7 middleware for league/oauth2-client

  • Sunday, June 25, 2017
  • by gabriel.somoza
  • Repository
  • 4 Watchers
  • 22 Stars
  • 14,435 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 11 Versions
  • 7 % Grown

The README.md

Abandoned

This is to inform all users that this package has been abandoned and will no longer receive any 
updates or maintenance. We highly recommend users to migrate to an alternative library package. 
We apologize for any inconvenience caused.

OAuth2 client middleware for league/oauth2-client

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version, (*1)

Author License, (*2)

PSR7 middleware that uses league/oauth2-client to authenticate requests with an OAuth2 server., (*3)

Installation

composer require somoza/oauth2-client-middleware

Usage

The current implementation indirectly depends on Guzzle 6 because it's a direct dependency of league/oauth2-client., (*4)

Using Guzzle:, (*5)

use Somoza\OAuth2Middleware\OAuth2Middleware;
use Somoza\OAuth2Middleware\TokenService\Bearer;

$stack = new \GuzzleHttp\HandlerStack();
$stack->setHandler(new CurlHandler());
$client = new \GuzzleHttp\Client(['handler' => $stack]);

// instantiate a provider, see league/oauth2-client docs
$provider = new GenericProvider(
    [
        'clientId' => 'your_client_id',
        'clientSecret' => 'your_client_secret',
        'urlAuthorize' => 'your_authorization_url',
        'urlAccessToken' => 'your_access_token_url',
        'urlResourceOwnerDetails' => 'your_resource_owner_url', 
    ], 
    [ 'httpClient' => $client ] // or don't pass it and let the oauth2-client create its own Guzzle client
);

// attach our oauth2 middleware
$bearerMiddleware = new OAuth2Middleware(
    new Bearer($provider), // use the Bearer token type
    [ // ignore (do not attempt to authorize) the following URLs
        $provider->getBaseAuthorizationUrl(),
        $provider->getBaseAccessTokenUrl(),
    ]
);
$stack->push($bearerMiddleware);

// if you want to debug, it might be useful to attach a PSR7 logger here

Caching the Access Token

A callback can be assigned to the middleware in order to save the access token for future use. Make sure you know about the security implications of storing an access token (do it at your own risk)., (*6)

Example:, (*7)

use Somoza\OAuth2Middleware\OAuth2Middleware;
use Somoza\OAuth2Middleware\TokenService\Bearer;
use League\OAuth2\Client\Token\AccessToken;

// see previous example for initialization
$tokenStore = new EncryptedCache(); // you can use whatever you want here
$token = null;
if ($tokenStore->contains($userId)) {
    $tokenData = json_decode($cache->fetch($userId));
    $token = new AccessToken($tokenData);
}

$bearerMiddleware = new OAuth2Middleware(
    new Bearer(
        $provider, // defined as in the "Usage" example
        $token, 
        function (AccessToken $newToken, AccessToken $oldToken) 
          use ($tokenStore, $userId) {
            // called whenever a new AccessToken is fetched
            $tokenStore->save($userId, $newToken->jsonSerialize());
        }
    ), 
);

$stack->push($bearerMiddleware);

License

MIT - see LICENSE.md, (*8)

The Versions

25/06 2017

dev-master

9999999-dev

OAuth2 PSR7 middleware for league/oauth2-client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gabriel Somoza

25/06 2017

0.3.0

0.3.0.0

OAuth2 PSR7 middleware for league/oauth2-client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gabriel Somoza

31/03 2017

0.2.6

0.2.6.0

OAuth2 PSR7 middleware for league/oauth2-client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gabriel Somoza

08/03 2017

dev-feature/refactor

dev-feature/refactor

OAuth2 PSR7 middleware for league/oauth2-client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gabriel Somoza

18/03 2016

0.2.5

0.2.5.0

OAuth2 PSR7 middleware for league/oauth2-client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gabriel Somoza

17/03 2016

0.2.4

0.2.4.0

OAuth2 PSR7 middleware for league/oauth2-client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gabriel Somoza

16/03 2016

0.2.3

0.2.3.0

OAuth2 PSR7 middleware for league/oauth2-client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gabriel Somoza

11/03 2016

0.2.2

0.2.2.0

OAuth2 PSR7 middleware for league/oauth2-client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gabriel Somoza

11/02 2016

0.2.1

0.2.1.0

OAuth2 PSR7 middleware for league/oauth2-client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gabriel Somoza

11/02 2016

0.2.0

0.2.0.0

OAuth2 PSR7 middleware for league/oauth2-client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gabriel Somoza

10/02 2016

0.1.0

0.1.0.0

OAuth2 PSR7 middleware for league/oauth2-client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Gabriel Somoza