chadicus / slim-oauth2-http
Bridge components for PSR-7 and bshaffer's OAuth2 Server http messages.
Installs: 386 865
Dependents: 5
Suggesters: 0
Security: 0
Stars: 18
Watchers: 5
Forks: 9
Open Issues: 2
Requires
- php: ^5.6 || ^7.0 || ^8.0
- bshaffer/oauth2-server-php: ^1.8
- laminas/laminas-diactoros: ^1.8 || ^2.0
Requires (Dev)
- phpunit/phpunit: ^5.7 || ^6.5 || ^9.6 || ^10.1
- squizlabs/php_codesniffer: ^3.7
Suggests
- chadicus/slim-oauth2-middleware: Adds OAuth2 middleware for API requests.
- chadicus/slim-oauth2-routes: Offers standard OAuth2 routes for slim applications
README
Static utilitiy classes to bridge PSR-7 http messages to OAuth2 Server requests and responses. While this libray is entended for use with Slim 3, it should work with any PSR-7 compatible framework.
Requirements
Chadicus\Slim\OAuth2\Http requires PHP 5.6 (or later).
Composer
To add the library as a local, per-project dependency use Composer! Simply add a dependency on chadicus/slim-oauth2-http
to your project's composer.json
file such as:
composer require chadicus/slim-oauth2-http
Contact
Developers may be contacted at:
Project Build
With a checkout of the code get Composer in your PATH and run:
composer install ./vendor/bin/phpunit ./vendor/bin/phpcs
Community
Available Operations
Convert a PSR-7 request to an OAuth2 request
use Chadicus\Slim\OAuth2\Http\RequestBridge; $oauth2Request = RequestBridge::toOAuth2($psrRequest);
Convert an OAuth2 response to a PSR-7 response.
use Chadicus\Slim\OAuth2\Http\ResponseBridge; $psr7Response = ResponseBridge::fromOAuth2($oauth2Request);
Example Integeration
Simple route for creating a new oauth2 access token
use Chadicus\Slim\OAuth2\Http\RequestBridge; use Chadicus\Slim\OAuth2\Http\ResponseBridge; use OAuth2; use OAuth2\GrantType; use OAuth2\Storage; use Slim; $storage = new Storage\Memory( [ 'client_credentials' => [ 'testClientId' => [ 'client_id' => 'testClientId', 'client_secret' => 'testClientSecret', ], ], ] ); $server = new OAuth2\Server( $storage, [ 'access_lifetime' => 3600, ], [ new GrantType\ClientCredentials($storage), ] ); $app = new Slim\App(); $app->post('/token', function ($psrRequest, $psrResponse, array $args) use ($app, $server) { //create an \OAuth2\Request from the current \Slim\Http\Request Object $oauth2Request = RequestBridge::toOAuth2($psrRequest); //Allow the oauth2 server instance to handle the oauth2 request $oauth2Response = $server->handleTokenRequest($oauth2Request), //Map the oauth2 response into the slim response return ResponseBridge::fromOAuth2($oauth2Response); });