borisguery / oauth2-server
0.1
2016-04-04 10:04 UTC
Requires
- php: ~5.5|~7.0
- beberlei/assert: ^2.4
- symfony/polyfill-php70: ^1.1
Requires (Dev)
- phpunit/phpunit: ^5.2
- scrutinizer/ocular: ~1.1
- squizlabs/php_codesniffer: ~2.3
This package is not auto-updated.
Last update: 2024-09-20 19:09:35 UTC
README
这里应该是您的描述。尽量限制在一到两段话内,并可能提及您支持哪些PSR,以避免与用户和贡献者产生混淆。
安装
通过Composer
$ composer require borisguery/oauth2-server
用法
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']); } }
测试
$ composer test
贡献
请参阅CONTRIBUTING以获取详细信息。
安全
如果您发现任何与安全相关的问题,请通过电子邮件guery.b@gmail.com联系,而不是使用问题跟踪器。
致谢
许可证
MIT许可证(MIT)。请参阅许可证文件获取更多信息。