https://github.com/chadicus/slim-oauth2-http
Bridge components for slim and oauth2 http messages.
https://github.com/chadicus/slim-oauth2-http
Last synced: about 1 year ago
JSON representation
Bridge components for slim and oauth2 http messages.
- Host: GitHub
- URL: https://github.com/chadicus/slim-oauth2-http
- Owner: chadicus
- License: mit
- Created: 2015-07-14T19:15:08.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2023-05-09T18:49:33.000Z (about 3 years ago)
- Last Synced: 2025-04-19T14:41:13.532Z (about 1 year ago)
- Language: PHP
- Size: 885 KB
- Stars: 18
- Watchers: 4
- Forks: 10
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Chadicus\Slim\OAuth2\Http
[](https://travis-ci.org/chadicus/slim-oauth2-http)
[](https://scrutinizer-ci.com/g/chadicus/slim-oauth2-http/?branch=master)
[](https://coveralls.io/github/chadicus/slim-oauth2-http?branch=master)
[](https://packagist.org/packages/chadicus/slim-oauth2-http)
[](https://packagist.org/packages/chadicus/slim-oauth2-http)
[](https://packagist.org/packages/chadicus/slim-oauth2-http)
[](https://packagist.org/packages/chadicus/slim-oauth2-http)
[](https://packagist.org/packages/chadicus/slim-oauth2-http)
[](https://packagist.org/packages/chadicus/slim-oauth2-http)
[](http://pholiophp.org/chadicus/slim-oauth2-http)
Static utilitiy classes to bridge [PSR-7](http://www.php-fig.org/psr/psr-7/) http messages to [OAuth2 Server](http://bshaffer.github.io/oauth2-server-php-docs/) requests and responses. While this libray is entended for use with [Slim 3](http://www.slimframework.com/), 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](http://getcomposer.org)! Simply add a dependency on `chadicus/slim-oauth2-http` to your project's `composer.json` file such as:
```sh
composer require chadicus/slim-oauth2-http
```
## Contact
Developers may be contacted at:
* [Pull Requests](https://github.com/chadicus/slim-oauth2-http/pulls)
* [Issues](https://github.com/chadicus/slim-oauth2-http/issues)
## Project Build
With a checkout of the code get [Composer](http://getcomposer.org) in your PATH and run:
```sh
composer install
./vendor/bin/phpunit
./vendor/bin/phpcs
```
## Community
[](https://gitter.im/slim-oauth2/Lobby#)
## Available Operations
### Convert a PSR-7 request to an OAuth2 request
```php
use Chadicus\Slim\OAuth2\Http\RequestBridge;
$oauth2Request = RequestBridge::toOAuth2($psrRequest);
```
### Convert an OAuth2 response to a PSR-7 response.
```php
use Chadicus\Slim\OAuth2\Http\ResponseBridge;
$psr7Response = ResponseBridge::fromOAuth2($oauth2Request);
```
## Example Integeration
### Simple route for creating a new oauth2 access token
```php
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);
});
```