borisguery/oauth2-server
Composer 安装命令:
composer require borisguery/oauth2-server
包简介
README 文档
README
This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention of what PSRs you support to avoid any confusion with users and contributors.
Install
Via Composer
$ composer require borisguery/oauth2-server
Usage
class OAuht2Controller { public function tokenAction(Request $request) { $sfPasswordGrantType = new SymfonySecurityPasswordGrantType( $this->container->get('security.user_provider'), $this->container->get('security.encoder_factory')->getEncoder(UserAccount::class) ); $clientStorage = new InMemoryClientStorage(); $defaultClient = new Client( 'test', null, [], ['password'] ); $clientStorage->save($defaultClient); $configuration = (new ResourceServerConfigurationBuilder()) ->setAccessTokenStorage(new InMemoryAccessTokenStorage()) ->setClientStorage($clientStorage) ->setRefreshStorage(new InMemoryRefreshTokenStorage()) ->setAccessTokenGenerator(new Php7CSPRNGStringGenerator()) ->addGrantType($sfPasswordGrantType) ->alwaysRequireAClient(true) ->alwaysGenerateARefreshToken(true) ->build() ->getResourceConfiguration() ; $resourceServer = new ResourceServer($configuration); $inputDataBag = SymfonyHttpFoundationRequestInputDataBagFactory::fromRequest($request); $attemptResult = $resourceServer->requestAccessToken( new TokenRequestAttempt($inputDataBag->getGrantType(), $inputDataBag) ); if ($attemptResult instanceof SuccessfulTokenRequestAttemptResult) { $statusCode = 200; $response = [ 'access_token' => $attemptResult->getAccessToken()->getToken(), 'expires_in' => $attemptResult->getAccessToken()->getExpiresIn(), 'token_type' => $attemptResult->getAccessToken()->getTokenType(), 'refresh_token' => $attemptResult->getRefreshToken() ? $attemptResult->getRefreshToken()->getToken() : null, ]; } elseif ($attemptResult instanceof FailedTokenRequestAttemptResult) { $statusCode = 400; $response = [ 'error' => (string) $attemptResult->getGrantDecision()->getError(), 'error_description' => $attemptResult->getGrantDecision()->getError()->getErrorDescription(), 'error_uri' => $attemptResult->getGrantDecision()->getError()->getErrorUri(), ]; } return new Response(json_encode($response), $statusCode, ['Content-Type' => 'application/json']); } }
Testing
$ composer test
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email guery.b@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 28
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 13
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-04-07