drbiko/slim-oauth2-http

PSR-7和bshaffer的OAuth2 Server http消息的桥接组件。

v3.1.8 2019-04-04 01:32 UTC

README

Build Status Code Quality Code Coverage

Latest Stable Version Latest Unstable Version License

Total Downloads Daily Downloads Monthly Downloads

Documentation

静态工具类,用于将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

联系

开发者可以通过以下方式联系

项目构建

检出代码后,将Composer添加到您的PATH中并运行

composer install
./vendor/bin/phpunit
./vendor/bin/phpcs

社区

Gitter

可用操作

将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);
});