承接 maksimovic/slim-oauth2-routes 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

maksimovic/slim-oauth2-routes

Composer 安装命令:

composer require maksimovic/slim-oauth2-routes

包简介

OAuth2 routes for use within a Slim Framework API

README 文档

README

Fork Notice: This is a maintained fork of the abandoned chadicus/slim-oauth2-routes package. Updated for PHP 8.1+ with fixes for PHP 8.4+ deprecations.

OAuth2 Server route callbacks for use within a Slim Framework API.

Requirements

PHP 8.1 or later.

Installation

composer require maksimovic/slim-oauth2-routes

A Note on Using Views

The authorize and receive-code routes require view objects. The given view object must implement a render() method such as the one found in slim/php-view.

Example Usage

use Chadicus\Slim\OAuth2\Routes;
use OAuth2;
use OAuth2\GrantType;
use OAuth2\Storage;
use Slim;
use Slim\Views;

// Set up the OAuth2 Server
$storage = new Storage\Pdo(['dsn' => $dsn, 'username' => $username, 'password' => $password]);
$server = new OAuth2\Server($storage);
$server->addGrantType(new GrantType\AuthorizationCode($storage));
$server->addGrantType(new GrantType\ClientCredentials($storage));

// Set up the Slim Application
$app = new Slim\App([
    'view' => new Views\PhpRenderer('/path/to/maksimovic/slim-oauth2-routes/templates'),
]);

$container = $app->getContainer();

$app->map(['GET', 'POST'], Routes\Authorize::ROUTE, new Routes\Authorize($server, $container['view']))->setName('authorize');
$app->post(Routes\Token::ROUTE, new Routes\Token($server))->setName('token');
$app->map(['GET', 'POST'], Routes\ReceiveCode::ROUTE, new Routes\ReceiveCode($container['view']))->setName('receive-code');
$app->post(Routes\Revoke::ROUTE, new Routes\Revoke($server))->setName('revoke');

$app->run();

Authorize and The UserIdProvider

Within the Authorization route, you can define a UserIdProviderInterface to extract the user_id from the incoming request. By default, the route will look in the GET query params.

use Chadicus\Slim\OAuth2\Routes\UserIdProviderInterface;
use Psr\Http\Message\ServerRequestInterface;

class ArgumentUserIdProvider implements UserIdProviderInterface
{
    public function getUserId(ServerRequestInterface $request, array $arguments = [])
    {
        return isset($arguments['user_id']) ? $arguments['user_id'] : null;
    }
}

$authorizeRoute = new Routes\Authorize($server, $view, 'authorize.phtml', new ArgumentUserIdProvider());
$app->map(['GET', 'POST'], Routes\Authorize::ROUTE, $authorizeRoute)->setName('authorize');

Development

composer install
composer test
composer test:coverage

License

MIT

统计信息

  • 总下载量: 2.52k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 1
  • 推荐数: 1

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固