texthtml / oauth2-provider
Symfony Security 组件的 OAuth2 提供者
v1.5.1
2016-10-26 16:27 UTC
Requires
- bshaffer/oauth2-server-httpfoundation-bridge: ^1.0
- bshaffer/oauth2-server-php: ^1.5
- symfony/security: ^2.5|^3.0
Requires (Dev)
- php-vfs/php-vfs: ^1.2
- phpspec/phpspec: ^2.0
- pimple/pimple: ^3.0
- silex/silex: ^2.0
Suggests
- silex/silex: Provide a light framework to build PHP applications
This package is auto-updated.
Last update: 2024-09-24 20:29:59 UTC
README
OAuth2 Provider 是一个用于 Symfony Security 组件的提供者,可用于构建受 OAuth2 保护的程序
安装
使用 Composer
composer require texthtml/oauth2-provider
与 Silex 2 的使用
有一个 Pimple 提供者可以用来保护 Silex 应用。您需要安装 Silex 2:composer require silex/silex "^2.0"
$app = new Silex\Application; $oAuth2Provider = new TH\OAuth2\Pimple\OAuth2ServerProvider; $app['security.entry_point.api.oauth2.realm'] = 'My App'; $app->register($oAuth2Provider, [ 'oauth2_server.storage.client' => function () use ($config) { return new TH\OAuth2\Storage\Memory\ClientMemoryStorage([ 'NICE_DEV_CLIENT' => [ 'name' => 'Nice Dev Client', 'redirect_uri' => 'http://..../my_oauth2_callback', ], ]); }, 'oauth2_server.storage.pdo_connection' => function(Application $app) { return new PDO('...'); }, ]); $app->mount('/auth/', $oAuth2Provider); $app['users.provider'] = [ // raw password is foo 'admin' => array('ROLE_ADMIN', '5FZ2Z8QIkA7UTZ4BYkoC+GsReLf569mSKDsfods6LYQ8t+a8EW9oaircfMpmaLbPBh4FOBiiFyLfuZmTSUwzZg=='), ]; $app->register(new Silex\Provider\SecurityServiceProvider, [ 'security.firewalls' => [ 'oauth.token' => [ 'pattern' => '^/auth/token', 'security' => false, ], 'oauth.authorize' => [ 'pattern' => '^/auth/authorize', 'http' => true, 'users' => $app['users.provider'], ], 'api' => [ 'pattern' => '^/api', 'stateless' => true, 'oauth2' => true, 'security' => true, 'users' => $app['users.provider'], ], ], ]);
与其他框架的使用
此包可用于任何使用 Symfony Security 组件的框架(例如:Symfony、Laravel、Silex 等)。但提供者 TH\OAuth2\Pimple\OAuth2ServerProvider
仅适用于 Silex 2。对于其他框架,您需要手动注册服务和挂载路由。
欢迎为这些框架提供提供者的 PR!