vsavritsky / slim-oauth2-http
PSR-7 和 bshaffer's OAuth2 Server http 消息的桥接组件。
v4.0.0
2023-01-20 21:13 UTC
Requires
- php: ^7.4 || ^8.0
- bshaffer/oauth2-server-php: ^1.8
- laminas/laminas-diactoros: ^2.8
Requires (Dev)
- php-coveralls/php-coveralls: ^2.5
- phpunit/phpunit: ^8.5
- squizlabs/php_codesniffer: ^3.2
Suggests
- chadicus/slim-oauth2-middleware: Adds OAuth2 middleware for API requests.
- chadicus/slim-oauth2-routes: Offers standard OAuth2 routes for slim applications
This package is not auto-updated.
Last update: 2024-09-29 05:49:15 UTC
README
用于将 PSR-7 http 消息桥接到 OAuth2 Server 请求和响应的静态实用类。尽管此库是为与 Slim 3 一起使用而扩展的,但它应该与任何 PSR-7 兼容的框架一起工作。
要求
Chadicus\Slim\OAuth2\Http 需要 PHP 5.6(或更高版本)。
Composer
要将库作为本地、项目特定的依赖项添加,请使用 Composer!只需将 chadicus/slim-oauth2-http
依赖项添加到项目 composer.json
文件中,例如
composer require chadicus/slim-oauth2-http
联系
开发者可以通过以下方式联系
项目构建
通过检出代码,在您的 PATH 中获取 Composer 并运行
composer install ./vendor/bin/phpunit ./vendor/bin/phpcs
社区
可用操作
将 PSR-7 请求转换为 OAuth2 请求
use Chadicus\Slim\OAuth2\Http\RequestBridge; $oauth2Request = RequestBridge::toOAuth2($psrRequest);
将 OAuth2 响应转换为 PSR-7 响应。
use Chadicus\Slim\OAuth2\Http\ResponseBridge; $psr7Response = ResponseBridge::fromOAuth2($oauth2Request);
示例集成
用于创建新的 OAuth2 访问令牌的简单路由
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); });