spomky-labs / oauth2-server-exception-manager-bundle
v5.0.1
2015-06-15 20:34 UTC
Requires
Requires (Dev)
- behat/behat: 3.*
- behat/symfony2-extension: *
- symfony/class-loader: ~2.3
- symfony/yaml: ~2.3
This package is not auto-updated.
Last update: 2015-08-17 10:39:37 UTC
README
此扩展包为您的 OAuth2 服务器添加了一个异常管理器。
它依赖于OAuth2 接口项目。
发布流程
发布流程在此描述。
先决条件
此库需要至少 PHP 5.4
和 Symfony v2.3
。
它已在以下环境中成功测试:
- PHP:
PHP 5.4
到PHP 5.6
,PHP 7
和HHVM
。 - Symfony:
v2.3.x
到v2.7.x
。
安装
安装此库的首选方式是依赖 Composer
composer require "spomky-labs/oauth2-server-exception-manager-bundle" "~5.0.0"
启用扩展包
在内核中启用扩展包
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( ... new SpomkyLabs\OAuth2ServerExceptionManagerBundle\SpomkyLabsOAuth2ServerExceptionManagerBundle(), ); }
配置
此扩展包不需要配置,所有选项都有默认值。
完整配置
sl_oauth2_exception_manager: realm: 'OAuth2 Server' manager: sl_oauth2_exception_manager.exception_manager.default
如何使用
此扩展包添加了一个新的服务 sl_oauth2_exception_manager.manager
。
您不需要做任何事情。让您的组件完成魔法!
如果您确实想要抛出自定义异常(例如在自定义授权类型中)
$exception = $this->container->get("sl_oauth2_exception_manager.manager")->getException(ExceptionManagerInterface::BAD_REQUEST, ExceptionManagerInterface::INVALID_GRANT, "Parameter 'foo' is missing", array("bar"=>"baz")); throw $exception;
方法 getException
的第一个参数指示异常类型。
支持的类型有
- ExceptionManagerInterface::AUTHENTICATE
- ExceptionManagerInterface::BAD_REQUEST
- ExceptionManagerInterface::NOT_IMPLEMENTED
- ExceptionManagerInterface::REDIRECT
- ExceptionManagerInterface::INTERNAL_SERVER_ERROR
支持的消息有
- ExceptionManagerInterface::INVALID_REQUEST
- ExceptionManagerInterface::INVALID_CLIENT
- ExceptionManagerInterface::INVALID_GRANT
- ExceptionManagerInterface::INVALID_SCOPE
- ExceptionManagerInterface::UNAUTHORIZED_CLIENT
- ExceptionManagerInterface::UNSUPPORTED_GRANT_TYPE
- ExceptionManagerInterface::ACCESS_DENIED
- ExceptionManagerInterface::UNSUPPORTED_RESPONSE_TYPE
- ExceptionManagerInterface::SERVER_ERROR
- ExceptionManagerInterface::TEMPORARILY_UNAVAILABLE
您还可以定义自己的消息。
贡献
欢迎对新功能、错误修复以及所有其他使此库出色的想法提出请求。请遵循以下最佳实践。
许可证
此库在MIT 许可证下发布。