├── .gitignore ├── .php_cs ├── .sami.php ├── .travis.yml ├── LICENSE ├── README.md ├── app ├── .htaccess ├── AppKernel.php ├── autoload.php └── config │ ├── config.yml │ ├── config_dev.yml │ ├── config_prod.yml │ ├── config_test.yml │ ├── routing.yml │ ├── routing_dev.yml │ └── security.yml ├── bin └── console ├── composer.json ├── phpunit.xml.dist ├── src ├── AuthBucketOAuth2Bundle.php ├── Controller │ ├── AuthorizationController.php │ ├── DebugController.php │ └── TokenController.php ├── DependencyInjection │ ├── AuthBucketOAuth2Extension.php │ ├── Configuration.php │ └── Security │ │ └── Factory │ │ ├── ResourceFactory.php │ │ └── TokenFactory.php ├── Entity │ ├── AbstractEntityRepository.php │ ├── AccessToken.php │ ├── AccessTokenRepository.php │ ├── Authorize.php │ ├── AuthorizeRepository.php │ ├── Client.php │ ├── ClientRepository.php │ ├── Code.php │ ├── CodeRepository.php │ ├── ModelManagerFactory.php │ ├── RefreshToken.php │ ├── RefreshTokenRepository.php │ ├── Scope.php │ └── ScopeRepository.php └── Resources │ ├── config │ ├── in_memory.yml │ ├── orm.yml │ ├── routing.yml │ └── services.yml │ ├── doc │ └── index.rst │ └── translations │ └── messages.fr.xlf ├── tests ├── AutoloadTest.php ├── Controller │ └── OAuth2ControllerTest.php ├── Exception │ ├── AccessDeniedExceptionTest.php │ ├── InvalidClientExceptionTest.php │ ├── InvalidGrantExceptionTest.php │ ├── InvalidRequestExceptionTest.php │ ├── InvalidScopeExceptionTest.php │ ├── ServerErrorExceptionTest.php │ ├── TemporarilyUnavailableExceptionTest.php │ ├── UnauthorizedClientExceptionTest.php │ ├── UnsupportedGrantTypeExceptionTest.php │ └── UnsupportedResponseTypeTest.php ├── GrantType │ ├── AuthorizationCodeGrantTypeHandlerTest.php │ ├── BarGrantTypeHandler.php │ ├── ClientCredentialsGrantTypeHandlerTest.php │ ├── FooGrantTypeHandler.php │ ├── GrantTypeHandlerFactoryTest.php │ ├── PasswordGrantTypeHandlerTest.php │ └── RefreshTokenGrantTypeHandlerTest.php ├── Model │ └── InMemoryTest.php ├── OAuth2Test.php ├── ResourceType │ ├── BarResourceTypeHandler.php │ ├── DebugEndpointResourceTypeHandlerTest.php │ ├── FooResourceTypeHandler.php │ ├── ModelResourceTypeHandlerTest.php │ └── ResourceTypeHandlerFactoryTest.php ├── ResponseType │ ├── BarResponseTypeHandler.php │ ├── CodeResponseTypeHandlerTest.php │ ├── FooResponseTypeHandler.php │ ├── ResponseTypeHandlerFactoryTest.php │ └── TokenResponseTypeHandlerTest.php ├── Security │ └── Authentication │ │ └── Provider │ │ └── ResourceProviderTest.php ├── TestBundle │ ├── Controller │ │ ├── DefaultController.php │ │ └── DemoController.php │ ├── DataFixtures │ │ └── ORM │ │ │ ├── AccessTokenFixture.php │ │ │ ├── AuthorizeFixture.php │ │ │ ├── ClientFixture.php │ │ │ ├── CodeFixture.php │ │ │ ├── RefreshTokenFixture.php │ │ │ ├── ScopeFixture.php │ │ │ └── UserFixture.php │ ├── Entity │ │ ├── AccessToken.php │ │ ├── AccessTokenRepository.php │ │ ├── Authorize.php │ │ ├── AuthorizeRepository.php │ │ ├── Client.php │ │ ├── ClientRepository.php │ │ ├── Code.php │ │ ├── CodeRepository.php │ │ ├── RefreshToken.php │ │ ├── RefreshTokenRepository.php │ │ ├── Scope.php │ │ ├── ScopeRepository.php │ │ ├── User.php │ │ └── UserRepository.php │ ├── Resources │ │ ├── config │ │ │ └── routing.yml │ │ └── views │ │ │ ├── demo │ │ │ ├── authorize.html.twig │ │ │ ├── grant_type │ │ │ │ ├── authorization_code.html.twig │ │ │ │ ├── client_credentials.html.twig │ │ │ │ ├── password.html.twig │ │ │ │ └── refresh_token.html.twig │ │ │ ├── index.html.twig │ │ │ ├── login.html.twig │ │ │ ├── resource_type │ │ │ │ ├── debug_endpoint.html.twig │ │ │ │ └── model.html.twig │ │ │ └── response_type │ │ │ │ ├── code.html.twig │ │ │ │ └── token.html.twig │ │ │ ├── getting-started │ │ │ └── index.html.twig │ │ │ ├── head.html.twig │ │ │ ├── html.html.twig │ │ │ ├── index.html.twig │ │ │ ├── page.html.twig │ │ │ ├── page_bottom.html.twig │ │ │ ├── page_top.html.twig │ │ │ ├── scripts.html.twig │ │ │ └── styles.html.twig │ └── TestBundle.php ├── TokenType │ ├── BarModelManagerFactory.php │ ├── BarTokenTypeHandler.php │ ├── BearerTokenTypeHandlerTest.php │ ├── FooModelManagerFactory.php │ ├── FooTokenTypeHandler.php │ ├── MacTokenTypeHandlerTest.php │ └── TokenTypeHandlerFactoryTest.php └── WebTestCase.php ├── var ├── bootstrap.php ├── bootstrap_test.php ├── cache │ ├── dev │ │ └── .empty │ ├── prod │ │ └── .empty │ └── test │ │ └── .empty └── logs │ └── .empty └── web ├── .htaccess ├── app.php ├── app_dev.php ├── apple-touch-icon.png ├── css └── style.css ├── favicon.ico └── robots.txt /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | composer.lock 3 | composer.phar 4 | var/cache/* 5 | var/logs/* 6 | vendor/ 7 | -------------------------------------------------------------------------------- /.php_cs: -------------------------------------------------------------------------------- 1 | true, 5 | 'array_syntax' => ['syntax' => 'short'], 6 | 'no_blank_lines_after_phpdoc' => false, 7 | 'ordered_class_elements' => true, 8 | 'phpdoc_order' => true, 9 | ]; 10 | 11 | $finder = PhpCsFixer\Finder::create() 12 | ->exclude('build') 13 | ->exclude('var/cache') 14 | ->exclude('var/log') 15 | ->exclude('vendor') 16 | ->ignoreDotFiles(false) 17 | ->ignoreVCS(true) 18 | ->in(__DIR__) 19 | ->notName('*.phar') 20 | ->notName('LICENSE') 21 | ->notName('README.md') 22 | ->notName('composer.*') 23 | ->notName('phpunit.xml*'); 24 | 25 | return PhpCsFixer\Config::create() 26 | ->setUsingCache(false) 27 | ->setRules($rules) 28 | ->setFinder($finder); 29 | -------------------------------------------------------------------------------- /.sami.php: -------------------------------------------------------------------------------- 1 | files() 9 | ->name('*.php') 10 | ->exclude('Resources') 11 | ->in($dir = 'src'); 12 | 13 | $versions = GitVersionCollection::create($dir) 14 | ->add('develop', 'develop branch') 15 | ->add('master', 'master branch') 16 | ->addFromTags('3.*') 17 | ->addFromTags('4.*') 18 | ->addFromTags('5.*'); 19 | 20 | return new Sami($iterator, [ 21 | 'theme' => 'default', 22 | 'versions' => $versions, 23 | 'title' => 'AuthBucket\Bundle\OAuth2Bundle API', 24 | 'build_dir' => __DIR__.'/build/sami/%version%', 25 | 'cache_dir' => __DIR__.'/build/cache/sami/%version%', 26 | 'include_parent_data' => false, 27 | 'default_opened_level' => 3, 28 | ]); 29 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | sudo: false 4 | 5 | dist: trusty 6 | 7 | language: php 8 | 9 | before_install: 10 | - sh -c "if [ $TRAVIS_PHP_VERSION != hhvm ]; then echo 'sendmail_path = /bin/true' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; fi" 11 | - travis_retry composer self-update 12 | - travis_retry composer global require --no-update consolidation/cgr:@stable 13 | - travis_retry composer global require --no-update hirak/prestissimo:@stable 14 | - travis_retry composer global update 15 | - export PATH="$HOME/.composer/vendor/bin:$PATH" 16 | - travis_retry cgr phpunit/phpunit ~5.7 17 | - travis_retry cgr satooshi/php-coveralls ~1.0 18 | 19 | install: 20 | - sh -c "if [ '$SYMFONY_DEPS_VERSION' = '3.2' ]; then sed -i 's/~3.2/3.2.*@dev/g' composer.json; fi" 21 | - sh -c "if [ '$SYMFONY_DEPS_VERSION' = '3.3' ]; then sed -i 's/~3.2/3.3.*@dev/g' composer.json; fi" 22 | - travis_retry composer install --prefer-source 23 | 24 | before_script: 25 | - mkdir -p build/logs 26 | - rm -rf app/cache/*/* 27 | 28 | script: 29 | - phpunit -c phpunit.xml.dist 30 | 31 | after_script: 32 | - travis_retry coveralls -v 33 | 34 | matrix: 35 | include: 36 | - php: 5.6 37 | - php: 5.6 38 | env: SYMFONY_DEPS_VERSION=3.2 39 | - php: 5.6 40 | env: SYMFONY_DEPS_VERSION=3.3 41 | - php: 7.0 42 | - php: 7.1 43 | - php: hhvm 44 | allow_failures: 45 | - php: hhvm 46 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Wong Hoi Sing Edison 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /app/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | Require all denied 3 | 4 | 5 | Order deny,allow 6 | Deny from all 7 | 8 | -------------------------------------------------------------------------------- /app/AppKernel.php: -------------------------------------------------------------------------------- 1 | getEnvironment(), ['prod', 'dev', 'test'])) { 18 | $bundles[] = new Symfony\Bundle\TwigBundle\TwigBundle(); 19 | $bundles[] = new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(); 20 | $bundles[] = new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(); 21 | $bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(); 22 | $bundles[] = new AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\TestBundle(); 23 | 24 | if (class_exists('Symfony\Bundle\WebServerBundle\WebServerBundle')) { 25 | $bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle(); 26 | } 27 | } 28 | 29 | return $bundles; 30 | } 31 | 32 | public function getCacheDir() 33 | { 34 | return dirname(__DIR__).'/var/cache/'.$this->getEnvironment(); 35 | } 36 | 37 | public function getLogDir() 38 | { 39 | return dirname(__DIR__).'/var/logs'; 40 | } 41 | 42 | public function registerContainerConfiguration(LoaderInterface $loader) 43 | { 44 | $loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml'); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /app/autoload.php: -------------------------------------------------------------------------------- 1 | getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: 'dev'); 19 | $debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod'; 20 | 21 | if ($debug) { 22 | Debug::enable(); 23 | } 24 | 25 | $kernel = new AppKernel($env, $debug); 26 | $application = new Application($kernel); 27 | $application->run($input); 28 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "authors": [ 3 | { 4 | "email": "hswong3i@pantarei-design.com", 5 | "homepage": "http://hswong3i.net", 6 | "name": "Wong Hoi Sing Edison" 7 | } 8 | ], 9 | "autoload": { 10 | "psr-4": { 11 | "AuthBucket\\Bundle\\OAuth2Bundle\\": "src/" 12 | } 13 | }, 14 | "autoload-dev": { 15 | "psr-4": { 16 | "AuthBucket\\Bundle\\OAuth2Bundle\\Tests\\": "tests/" 17 | } 18 | }, 19 | "description": "Symfony OAuth2Bundle", 20 | "extra": { 21 | "branch-alias": { 22 | "dev-develop": "5.x-dev", 23 | "dev-master": "5.0.x-dev" 24 | } 25 | }, 26 | "homepage": "https://github.com/authbucket/oauth2-symfony-bundle", 27 | "keywords": [ 28 | "oauth2", 29 | "psr-1", 30 | "psr-2", 31 | "psr-3", 32 | "psr-4", 33 | "symfony" 34 | ], 35 | "license": "MIT", 36 | "name": "authbucket/oauth2-symfony-bundle", 37 | "require": { 38 | "authbucket/oauth2-php": "~5.0.0-alpha4", 39 | "php": ">=5.5.9", 40 | "symfony/framework-bundle": "~3.2", 41 | "symfony/monolog-bundle": "~3.0", 42 | "symfony/security-bundle": "~3.2" 43 | }, 44 | "require-dev": { 45 | "doctrine/doctrine-bundle": "~1.6", 46 | "doctrine/doctrine-fixtures-bundle": "~2.3", 47 | "doctrine/orm": "~2.5", 48 | "ext-pdo_sqlite": "*", 49 | "sensio/distribution-bundle": "~5.0", 50 | "sensio/framework-extra-bundle": "~3.0", 51 | "symfony/phpunit-bridge": "~3.2", 52 | "symfony/swiftmailer-bundle": "~2.3", 53 | "symfony/symfony": "~3.2", 54 | "twig/extensions": "~1.0" 55 | }, 56 | "type": "symfony-bundle" 57 | } 58 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 14 | 15 | 16 | 17 | ./tests 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | ./src 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/AuthBucketOAuth2Bundle.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\DependencyInjection\AuthBucketOAuth2Extension; 15 | use AuthBucket\Bundle\OAuth2Bundle\DependencyInjection\Security\Factory\ResourceFactory; 16 | use AuthBucket\Bundle\OAuth2Bundle\DependencyInjection\Security\Factory\TokenFactory; 17 | use Symfony\Component\DependencyInjection\ContainerBuilder; 18 | use Symfony\Component\HttpKernel\Bundle\Bundle; 19 | 20 | class AuthBucketOAuth2Bundle extends Bundle 21 | { 22 | public function __construct() 23 | { 24 | $this->extension = new AuthBucketOAuth2Extension(); 25 | } 26 | 27 | public function build(ContainerBuilder $container) 28 | { 29 | parent::build($container); 30 | 31 | $extension = $container->getExtension('security'); 32 | $extension->addSecurityListenerFactory(new ResourceFactory()); 33 | $extension->addSecurityListenerFactory(new TokenFactory()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Controller/AuthorizationController.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Controller; 13 | 14 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; 15 | use Symfony\Component\HttpFoundation\Request; 16 | 17 | class AuthorizationController extends Controller 18 | { 19 | public function indexAction(Request $request) 20 | { 21 | return $this->get('authbucket_oauth2.authorization_controller')->indexAction($request); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Controller/DebugController.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Controller; 13 | 14 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; 15 | use Symfony\Component\HttpFoundation\Request; 16 | 17 | class DebugController extends Controller 18 | { 19 | public function indexAction(Request $request) 20 | { 21 | return $this->get('authbucket_oauth2.debug_controller')->indexAction($request); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Controller/TokenController.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Controller; 13 | 14 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; 15 | use Symfony\Component\HttpFoundation\Request; 16 | 17 | class TokenController extends Controller 18 | { 19 | public function indexAction(Request $request) 20 | { 21 | return $this->get('authbucket_oauth2.token_controller')->indexAction($request); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/DependencyInjection/AuthBucketOAuth2Extension.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\DependencyInjection; 13 | 14 | use Symfony\Component\Config\FileLocator; 15 | use Symfony\Component\DependencyInjection\ContainerBuilder; 16 | use Symfony\Component\DependencyInjection\Loader; 17 | use Symfony\Component\DependencyInjection\Reference; 18 | use Symfony\Component\HttpKernel\DependencyInjection\Extension; 19 | 20 | /** 21 | * This is the class that loads and manages your bundle configuration. 22 | * 23 | * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} 24 | */ 25 | class AuthBucketOAuth2Extension extends Extension 26 | { 27 | /** 28 | * {@inheritdoc} 29 | */ 30 | public function load(array $configs, ContainerBuilder $container) 31 | { 32 | $config = $this->processConfiguration( 33 | new Configuration(), 34 | $configs 35 | ); 36 | 37 | $loader = new Loader\YamlFileLoader( 38 | $container, 39 | new FileLocator(__DIR__.'/../Resources/config') 40 | ); 41 | 42 | $loader->load('services.yml'); 43 | 44 | $driver = $config['driver'] ?: 'in_memory'; 45 | if (in_array($driver, ['in_memory', 'orm'])) { 46 | $loader->load(sprintf('%s.yml', $driver)); 47 | } 48 | unset($config['driver']); 49 | 50 | $userProvider = $config['user_provider'] ?: null; 51 | if ($userProvider) { 52 | $container->getDefinition('authbucket_oauth2.grant_type_handler.factory') 53 | ->replaceArgument(5, new Reference($userProvider)); 54 | } 55 | unset($config['user_provider']); 56 | 57 | foreach (array_filter($config) as $key => $value) { 58 | $container->setParameter('authbucket_oauth2.'.$key, $value); 59 | } 60 | } 61 | 62 | public function getAlias() 63 | { 64 | return 'authbucket_oauth2'; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/DependencyInjection/Configuration.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\DependencyInjection; 13 | 14 | use Symfony\Component\Config\Definition\Builder\TreeBuilder; 15 | use Symfony\Component\Config\Definition\ConfigurationInterface; 16 | 17 | /** 18 | * This is the class that validates and merges configuration from your app/config files. 19 | * 20 | * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class} 21 | */ 22 | class Configuration implements ConfigurationInterface 23 | { 24 | /** 25 | * {@inheritdoc} 26 | */ 27 | public function getConfigTreeBuilder() 28 | { 29 | $treeBuilder = new TreeBuilder(); 30 | $rootNode = $treeBuilder->root('oauth2'); 31 | 32 | $rootNode 33 | ->children() 34 | ->scalarNode('driver')->defaultNull()->end() 35 | ->scalarNode('user_provider')->defaultNull()->end() 36 | ->arrayNode('model') 37 | ->prototype('scalar')->end() 38 | ->end() 39 | ->arrayNode('response_type_handler') 40 | ->prototype('scalar')->end() 41 | ->end() 42 | ->arrayNode('grant_type_handler') 43 | ->prototype('scalar')->end() 44 | ->end() 45 | ->arrayNode('token_type_handler') 46 | ->prototype('scalar')->end() 47 | ->end() 48 | ->arrayNode('resource_type_handler') 49 | ->prototype('scalar')->end() 50 | ->end() 51 | ->end(); 52 | 53 | return $treeBuilder; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/DependencyInjection/Security/Factory/ResourceFactory.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\DependencyInjection\Security\Factory; 13 | 14 | use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface; 15 | use Symfony\Component\Config\Definition\Builder\NodeDefinition; 16 | use Symfony\Component\DependencyInjection\ContainerBuilder; 17 | use Symfony\Component\DependencyInjection\DefinitionDecorator; 18 | 19 | class ResourceFactory implements SecurityFactoryInterface 20 | { 21 | public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint) 22 | { 23 | $config = array_merge([ 24 | 'resource_type' => 'model', 25 | 'scope' => [], 26 | 'options' => [], 27 | ], (array) $config); 28 | 29 | $providerId = 'security.authentication.provider.resource.'.$id; 30 | $container 31 | ->setDefinition($providerId, new DefinitionDecorator('security.authentication.provider.resource')) 32 | ->replaceArgument(0, $id) 33 | ->replaceArgument(2, $config['resource_type']) 34 | ->replaceArgument(3, $config['scope']) 35 | ->replaceArgument(4, $config['options']); 36 | 37 | $listenerId = 'security.authentication.listener.resource.'.$id; 38 | $container->setDefinition($listenerId, new DefinitionDecorator('security.authentication.listener.resource')) 39 | ->replaceArgument(0, $id); 40 | 41 | return [$providerId, $listenerId, $defaultEntryPoint]; 42 | } 43 | 44 | public function getPosition() 45 | { 46 | return 'pre_auth'; 47 | } 48 | 49 | public function getKey() 50 | { 51 | return 'oauth2-resource'; 52 | } 53 | 54 | public function addConfiguration(NodeDefinition $node) 55 | { 56 | $node 57 | ->children() 58 | ->scalarNode('resource_type')->defaultValue('model')->end() 59 | ->end(); 60 | 61 | $node 62 | ->children() 63 | ->arrayNode('scope') 64 | ->prototype('scalar')->end() 65 | ->end() 66 | ->end(); 67 | 68 | $node 69 | ->children() 70 | ->arrayNode('options') 71 | ->useAttributeAsKey('key') 72 | ->prototype('scalar')->end() 73 | ->end() 74 | ->end(); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/DependencyInjection/Security/Factory/TokenFactory.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\DependencyInjection\Security\Factory; 13 | 14 | use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface; 15 | use Symfony\Component\Config\Definition\Builder\NodeDefinition; 16 | use Symfony\Component\DependencyInjection\ContainerBuilder; 17 | use Symfony\Component\DependencyInjection\DefinitionDecorator; 18 | 19 | class TokenFactory implements SecurityFactoryInterface 20 | { 21 | public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint) 22 | { 23 | $providerId = 'security.authentication.provider.token.'.$id; 24 | $container->setDefinition($providerId, new DefinitionDecorator('security.authentication.provider.token')) 25 | ->replaceArgument(0, $id); 26 | 27 | $listenerId = 'security.authentication.listener.token.'.$id; 28 | $container->setDefinition($listenerId, new DefinitionDecorator('security.authentication.listener.token')) 29 | ->replaceArgument(0, $id); 30 | 31 | return [$providerId, $listenerId, $defaultEntryPoint]; 32 | } 33 | 34 | public function getPosition() 35 | { 36 | return 'pre_auth'; 37 | } 38 | 39 | public function getKey() 40 | { 41 | return 'oauth2-token'; 42 | } 43 | 44 | public function addConfiguration(NodeDefinition $node) 45 | { 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Entity/AbstractEntityRepository.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Entity; 13 | 14 | use AuthBucket\OAuth2\Model\ModelInterface; 15 | use AuthBucket\OAuth2\Model\ModelManagerInterface; 16 | use Doctrine\ORM\EntityRepository; 17 | 18 | /** 19 | * AbstractEntityRepository. 20 | * 21 | * This class was generated by the Doctrine ORM. Add your own custom 22 | * repository methods below. 23 | */ 24 | class AbstractEntityRepository extends EntityRepository implements ModelManagerInterface 25 | { 26 | public function createModel(ModelInterface $model) 27 | { 28 | $this->getEntityManager()->persist($model); 29 | $this->getEntityManager()->flush(); 30 | 31 | return $model; 32 | } 33 | 34 | public function readModelAll() 35 | { 36 | return $this->findAll(); 37 | } 38 | 39 | public function readModelBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) 40 | { 41 | return $this->findBy($criteria, $orderBy, $limit, $offset); 42 | } 43 | 44 | public function readModelOneBy(array $criteria, array $orderBy = null) 45 | { 46 | return $this->findOneBy($criteria, $orderBy); 47 | } 48 | 49 | public function updateModel(ModelInterface $model) 50 | { 51 | $this->getEntityManager()->flush(); 52 | 53 | return $model; 54 | } 55 | 56 | public function deleteModel(ModelInterface $model) 57 | { 58 | $this->getEntityManager()->remove($model); 59 | $this->getEntityManager()->flush(); 60 | 61 | return $model; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Entity/AccessToken.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Entity; 13 | 14 | use AuthBucket\OAuth2\Model\AccessTokenInterface; 15 | use Doctrine\ORM\Mapping as ORM; 16 | 17 | /** 18 | * AccessToken. 19 | * 20 | * @ORM\MappedSuperclass(repositoryClass="AuthBucket\Bundle\OAuth2Bundle\Entity\AccessTokenRepository") 21 | */ 22 | abstract class AccessToken implements AccessTokenInterface 23 | { 24 | /** 25 | * @var string 26 | * 27 | * @ORM\Column(name="access_token", type="string", length=255) 28 | */ 29 | protected $accessToken; 30 | 31 | /** 32 | * @var string 33 | * 34 | * @ORM\Column(name="token_type", type="string", length=255) 35 | */ 36 | protected $tokenType; 37 | 38 | /** 39 | * @var string 40 | * 41 | * @ORM\Column(name="client_id", type="string", length=255) 42 | */ 43 | protected $clientId; 44 | 45 | /** 46 | * @var string 47 | * 48 | * @ORM\Column(name="username", type="string", length=255) 49 | */ 50 | protected $username; 51 | 52 | /** 53 | * @var \DateTime 54 | * 55 | * @ORM\Column(name="expires", type="datetime") 56 | */ 57 | protected $expires; 58 | 59 | /** 60 | * @var array 61 | * 62 | * @ORM\Column(name="scope", type="array") 63 | */ 64 | protected $scope; 65 | 66 | /** 67 | * Set access_token. 68 | * 69 | * @param string $accessToken 70 | * 71 | * @return AccessToken 72 | */ 73 | public function setAccessToken($accessToken) 74 | { 75 | $this->accessToken = $accessToken; 76 | 77 | return $this; 78 | } 79 | 80 | /** 81 | * Get access_token. 82 | * 83 | * @return string 84 | */ 85 | public function getAccessToken() 86 | { 87 | return $this->accessToken; 88 | } 89 | 90 | /** 91 | * Set token_type. 92 | * 93 | * @param string $tokenType 94 | * 95 | * @return AccessToken 96 | */ 97 | public function setTokenType($tokenType) 98 | { 99 | $this->tokenType = $tokenType; 100 | 101 | return $this; 102 | } 103 | 104 | /** 105 | * Get token_type. 106 | * 107 | * @return string 108 | */ 109 | public function getTokenType() 110 | { 111 | return $this->tokenType; 112 | } 113 | 114 | /** 115 | * Set client_id. 116 | * 117 | * @param string $clientId 118 | * 119 | * @return AccessToken 120 | */ 121 | public function setClientId($clientId) 122 | { 123 | $this->clientId = $clientId; 124 | 125 | return $this; 126 | } 127 | 128 | /** 129 | * Get client_id. 130 | * 131 | * @return string 132 | */ 133 | public function getClientId() 134 | { 135 | return $this->clientId; 136 | } 137 | 138 | /** 139 | * Set username. 140 | * 141 | * @param string $username 142 | * 143 | * @return AccessToken 144 | */ 145 | public function setUsername($username) 146 | { 147 | $this->username = $username; 148 | 149 | return $this; 150 | } 151 | 152 | /** 153 | * Get username. 154 | * 155 | * @return string 156 | */ 157 | public function getUsername() 158 | { 159 | return $this->username; 160 | } 161 | 162 | /** 163 | * Set expires. 164 | * 165 | * @param \DateTime $expires 166 | * 167 | * @return AccessToken 168 | */ 169 | public function setExpires($expires) 170 | { 171 | $this->expires = $expires; 172 | 173 | return $this; 174 | } 175 | 176 | /** 177 | * Get expires. 178 | * 179 | * @return \DateTime 180 | */ 181 | public function getExpires() 182 | { 183 | return $this->expires; 184 | } 185 | 186 | /** 187 | * Set scope. 188 | * 189 | * @param array $scope 190 | * 191 | * @return AccessToken 192 | */ 193 | public function setScope($scope) 194 | { 195 | $this->scope = $scope; 196 | 197 | return $this; 198 | } 199 | 200 | /** 201 | * Get scope. 202 | * 203 | * @return array 204 | */ 205 | public function getScope() 206 | { 207 | return $this->scope; 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /src/Entity/AccessTokenRepository.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Entity; 13 | 14 | use AuthBucket\OAuth2\Model\AccessTokenManagerInterface; 15 | 16 | /** 17 | * AccessTokenRepository. 18 | * 19 | * This class was generated by the Doctrine ORM. Add your own custom 20 | * repository methods below. 21 | */ 22 | class AccessTokenRepository extends AbstractEntityRepository implements AccessTokenManagerInterface 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /src/Entity/Authorize.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Entity; 13 | 14 | use AuthBucket\OAuth2\Model\AuthorizeInterface; 15 | use Doctrine\ORM\Mapping as ORM; 16 | 17 | /** 18 | * Authorize. 19 | * 20 | * @ORM\MappedSuperclass(repositoryClass="AuthBucket\Bundle\OAuth2Bundle\Entity\AuthorizeRepository") 21 | */ 22 | abstract class Authorize implements AuthorizeInterface 23 | { 24 | /** 25 | * @var string 26 | * 27 | * @ORM\Column(name="client_id", type="string", length=255) 28 | */ 29 | protected $clientId; 30 | 31 | /** 32 | * @var string 33 | * 34 | * @ORM\Column(name="username", type="string", length=255) 35 | */ 36 | protected $username; 37 | 38 | /** 39 | * @var array 40 | * 41 | * @ORM\Column(name="scope", type="array") 42 | */ 43 | protected $scope; 44 | 45 | /** 46 | * Set client_id. 47 | * 48 | * @param string $clientId 49 | * 50 | * @return Authorize 51 | */ 52 | public function setClientId($clientId) 53 | { 54 | $this->clientId = $clientId; 55 | 56 | return $this; 57 | } 58 | 59 | /** 60 | * Get client_id. 61 | * 62 | * @return string 63 | */ 64 | public function getClientId() 65 | { 66 | return $this->clientId; 67 | } 68 | 69 | /** 70 | * Set username. 71 | * 72 | * @param string $username 73 | * 74 | * @return Authorize 75 | */ 76 | public function setUsername($username) 77 | { 78 | $this->username = $username; 79 | 80 | return $this; 81 | } 82 | 83 | /** 84 | * Get username. 85 | * 86 | * @return string 87 | */ 88 | public function getUsername() 89 | { 90 | return $this->username; 91 | } 92 | 93 | /** 94 | * Set scope. 95 | * 96 | * @param array $scope 97 | * 98 | * @return Authorize 99 | */ 100 | public function setScope($scope) 101 | { 102 | $this->scope = $scope; 103 | 104 | return $this; 105 | } 106 | 107 | /** 108 | * Get scope. 109 | * 110 | * @return array 111 | */ 112 | public function getScope() 113 | { 114 | return $this->scope; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/Entity/AuthorizeRepository.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Entity; 13 | 14 | use AuthBucket\OAuth2\Model\AuthorizeManagerInterface; 15 | 16 | /** 17 | * AuthorizeRepository. 18 | * 19 | * This class was generated by the Doctrine ORM. Add your own custom 20 | * repository methods below. 21 | */ 22 | class AuthorizeRepository extends AbstractEntityRepository implements AuthorizeManagerInterface 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /src/Entity/Client.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Entity; 13 | 14 | use AuthBucket\OAuth2\Model\ClientInterface; 15 | use Doctrine\ORM\Mapping as ORM; 16 | 17 | /** 18 | * Client. 19 | * 20 | * @ORM\MappedSuperclass(repositoryClass="AuthBucket\Bundle\OAuth2Bundle\Entity\ClientRepository") 21 | */ 22 | abstract class Client implements ClientInterface 23 | { 24 | /** 25 | * @var string 26 | * 27 | * @ORM\Column(name="client_id", type="string", length=255) 28 | */ 29 | protected $clientId; 30 | 31 | /** 32 | * @var string 33 | * 34 | * @ORM\Column(name="client_secret", type="string", length=255) 35 | */ 36 | protected $clientSecret; 37 | 38 | /** 39 | * @var string 40 | * 41 | * @ORM\Column(name="redirect_uri", type="text") 42 | */ 43 | protected $redirectUri; 44 | 45 | /** 46 | * Set client_id. 47 | * 48 | * @param string $clientId 49 | * 50 | * @return Client 51 | */ 52 | public function setClientId($clientId) 53 | { 54 | $this->clientId = $clientId; 55 | 56 | return $this; 57 | } 58 | 59 | /** 60 | * Get client_id. 61 | * 62 | * @return string 63 | */ 64 | public function getClientId() 65 | { 66 | return $this->clientId; 67 | } 68 | 69 | /** 70 | * Set client_secret. 71 | * 72 | * @param string $clientSecret 73 | * 74 | * @return Client 75 | */ 76 | public function setClientSecret($clientSecret) 77 | { 78 | $this->clientSecret = $clientSecret; 79 | 80 | return $this; 81 | } 82 | 83 | /** 84 | * Get client_secret. 85 | * 86 | * @return string 87 | */ 88 | public function getClientSecret() 89 | { 90 | return $this->clientSecret; 91 | } 92 | 93 | /** 94 | * Set redirect_uri. 95 | * 96 | * @param string $redirectUri 97 | * 98 | * @return Client 99 | */ 100 | public function setRedirectUri($redirectUri) 101 | { 102 | $this->redirectUri = $redirectUri; 103 | 104 | return $this; 105 | } 106 | 107 | /** 108 | * Get redirect_uri. 109 | * 110 | * @return string 111 | */ 112 | public function getRedirectUri() 113 | { 114 | return $this->redirectUri; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/Entity/ClientRepository.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Entity; 13 | 14 | use AuthBucket\OAuth2\Model\ClientManagerInterface; 15 | 16 | /** 17 | * ClientRepository. 18 | * 19 | * This class was generated by the Doctrine ORM. Add your own custom 20 | * repository methods below. 21 | */ 22 | class ClientRepository extends AbstractEntityRepository implements ClientManagerInterface 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /src/Entity/Code.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Entity; 13 | 14 | use AuthBucket\OAuth2\Model\CodeInterface; 15 | use Doctrine\ORM\Mapping as ORM; 16 | 17 | /** 18 | * Code. 19 | * 20 | * @ORM\MappedSuperclass(repositoryClass="AuthBucket\Bundle\OAuth2Bundle\Entity\CodeRepository") 21 | */ 22 | abstract class Code implements CodeInterface 23 | { 24 | /** 25 | * @var string 26 | * 27 | * @ORM\Column(name="code", type="string", length=255) 28 | */ 29 | protected $code; 30 | 31 | /** 32 | * @var string 33 | * 34 | * @ORM\Column(name="client_id", type="string", length=255) 35 | */ 36 | protected $clientId; 37 | 38 | /** 39 | * @var string 40 | * 41 | * @ORM\Column(name="username", type="string", length=255) 42 | */ 43 | protected $username; 44 | 45 | /** 46 | * @var string 47 | * 48 | * @ORM\Column(name="redirect_uri", type="text") 49 | */ 50 | protected $redirectUri; 51 | 52 | /** 53 | * @var \DateTime 54 | * 55 | * @ORM\Column(name="expires", type="datetime") 56 | */ 57 | protected $expires; 58 | 59 | /** 60 | * @var array 61 | * 62 | * @ORM\Column(name="scope", type="array") 63 | */ 64 | protected $scope; 65 | 66 | /** 67 | * Set code. 68 | * 69 | * @param string $code 70 | * 71 | * @return Code 72 | */ 73 | public function setCode($code) 74 | { 75 | $this->code = $code; 76 | 77 | return $this; 78 | } 79 | 80 | /** 81 | * Get code. 82 | * 83 | * @return string 84 | */ 85 | public function getCode() 86 | { 87 | return $this->code; 88 | } 89 | 90 | /** 91 | * Set client_id. 92 | * 93 | * @param string $clientId 94 | * 95 | * @return Code 96 | */ 97 | public function setClientId($clientId) 98 | { 99 | $this->clientId = $clientId; 100 | 101 | return $this; 102 | } 103 | 104 | /** 105 | * Get client_id. 106 | * 107 | * @return string 108 | */ 109 | public function getClientId() 110 | { 111 | return $this->clientId; 112 | } 113 | 114 | /** 115 | * Set username. 116 | * 117 | * @param string $username 118 | * 119 | * @return Code 120 | */ 121 | public function setUsername($username) 122 | { 123 | $this->username = $username; 124 | 125 | return $this; 126 | } 127 | 128 | /** 129 | * Get username. 130 | * 131 | * @return string 132 | */ 133 | public function getUsername() 134 | { 135 | return $this->username; 136 | } 137 | 138 | /** 139 | * Set redirect_uri. 140 | * 141 | * @param string $redirectUri 142 | * 143 | * @return Code 144 | */ 145 | public function setRedirectUri($redirectUri) 146 | { 147 | $this->redirectUri = $redirectUri; 148 | 149 | return $this; 150 | } 151 | 152 | /** 153 | * Get redirect_uri. 154 | * 155 | * @return string 156 | */ 157 | public function getRedirectUri() 158 | { 159 | return $this->redirectUri; 160 | } 161 | 162 | /** 163 | * Set expires. 164 | * 165 | * @param \DateTime $expires 166 | * 167 | * @return Code 168 | */ 169 | public function setExpires($expires) 170 | { 171 | $this->expires = $expires; 172 | 173 | return $this; 174 | } 175 | 176 | /** 177 | * Get expires. 178 | * 179 | * @return \DateTime 180 | */ 181 | public function getExpires() 182 | { 183 | return $this->expires; 184 | } 185 | 186 | /** 187 | * Set scope. 188 | * 189 | * @param array $scope 190 | * 191 | * @return Code 192 | */ 193 | public function setScope($scope) 194 | { 195 | $this->scope = $scope; 196 | 197 | return $this; 198 | } 199 | 200 | /** 201 | * Get scope. 202 | * 203 | * @return array 204 | */ 205 | public function getScope() 206 | { 207 | return $this->scope; 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /src/Entity/CodeRepository.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Entity; 13 | 14 | use AuthBucket\OAuth2\Model\CodeManagerInterface; 15 | 16 | /** 17 | * CodeRepository. 18 | * 19 | * This class was generated by the Doctrine ORM. Add your own custom 20 | * repository methods below. 21 | */ 22 | class CodeRepository extends AbstractEntityRepository implements CodeManagerInterface 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /src/Entity/ModelManagerFactory.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Entity; 13 | 14 | use AuthBucket\OAuth2\Exception\ServerErrorException; 15 | use AuthBucket\OAuth2\Model\ModelManagerFactoryInterface; 16 | use AuthBucket\OAuth2\Model\ModelManagerInterface; 17 | use Doctrine\ORM\EntityManager; 18 | 19 | /** 20 | * OAuth2 model manager factory implemention. 21 | * 22 | * @author Wong Hoi Sing Edison 23 | */ 24 | class ModelManagerFactory implements ModelManagerFactoryInterface 25 | { 26 | protected $managers; 27 | 28 | public function __construct(EntityManager $em, array $models = []) 29 | { 30 | $managers = []; 31 | foreach ($models as $type => $model) { 32 | $manager = $em->getRepository($model); 33 | if (!$manager instanceof ModelManagerInterface) { 34 | throw new ServerErrorException(); 35 | } 36 | $managers[$type] = $manager; 37 | } 38 | 39 | $this->managers = $managers; 40 | } 41 | 42 | public function getModelManager($type) 43 | { 44 | if (!isset($this->managers[$type])) { 45 | throw new ServerErrorException(); 46 | } 47 | 48 | return $this->managers[$type]; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Entity/RefreshToken.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Entity; 13 | 14 | use AuthBucket\OAuth2\Model\RefreshTokenInterface; 15 | use Doctrine\ORM\Mapping as ORM; 16 | 17 | /** 18 | * RefreshToken. 19 | * 20 | * @ORM\MappedSuperclass(repositoryClass="AuthBucket\Bundle\OAuth2Bundle\Entity\RefreshTokenRepository") 21 | */ 22 | abstract class RefreshToken implements RefreshTokenInterface 23 | { 24 | /** 25 | * @var string 26 | * 27 | * @ORM\Column(name="refresh_token", type="string", length=255) 28 | */ 29 | protected $refreshToken; 30 | 31 | /** 32 | * @var string 33 | * 34 | * @ORM\Column(name="client_id", type="string", length=255) 35 | */ 36 | protected $clientId; 37 | 38 | /** 39 | * @var string 40 | * 41 | * @ORM\Column(name="username", type="string", length=255) 42 | */ 43 | protected $username; 44 | 45 | /** 46 | * @var \DateTime 47 | * 48 | * @ORM\Column(name="expires", type="datetime") 49 | */ 50 | protected $expires; 51 | 52 | /** 53 | * @var array 54 | * 55 | * @ORM\Column(name="scope", type="array") 56 | */ 57 | protected $scope; 58 | 59 | /** 60 | * Set refresh_token. 61 | * 62 | * @param string $refreshToken 63 | * 64 | * @return RefreshToken 65 | */ 66 | public function setRefreshToken($refreshToken) 67 | { 68 | $this->refreshToken = $refreshToken; 69 | 70 | return $this; 71 | } 72 | 73 | /** 74 | * Get refresh_token. 75 | * 76 | * @return string 77 | */ 78 | public function getRefreshToken() 79 | { 80 | return $this->refreshToken; 81 | } 82 | 83 | /** 84 | * Set client_id. 85 | * 86 | * @param string $clientId 87 | * 88 | * @return RefreshToken 89 | */ 90 | public function setClientId($clientId) 91 | { 92 | $this->clientId = $clientId; 93 | 94 | return $this; 95 | } 96 | 97 | /** 98 | * Get client_id. 99 | * 100 | * @return string 101 | */ 102 | public function getClientId() 103 | { 104 | return $this->clientId; 105 | } 106 | 107 | /** 108 | * Set username. 109 | * 110 | * @param string $username 111 | * 112 | * @return RefreshToken 113 | */ 114 | public function setUsername($username) 115 | { 116 | $this->username = $username; 117 | 118 | return $this; 119 | } 120 | 121 | /** 122 | * Get username. 123 | * 124 | * @return string 125 | */ 126 | public function getUsername() 127 | { 128 | return $this->username; 129 | } 130 | 131 | /** 132 | * Set expires. 133 | * 134 | * @param \DateTime $expires 135 | * 136 | * @return RefreshToken 137 | */ 138 | public function setExpires($expires) 139 | { 140 | $this->expires = $expires; 141 | 142 | return $this; 143 | } 144 | 145 | /** 146 | * Get expires. 147 | * 148 | * @return \DateTime 149 | */ 150 | public function getExpires() 151 | { 152 | return $this->expires; 153 | } 154 | 155 | /** 156 | * Set scope. 157 | * 158 | * @param array $scope 159 | * 160 | * @return RefreshToken 161 | */ 162 | public function setScope($scope) 163 | { 164 | $this->scope = $scope; 165 | 166 | return $this; 167 | } 168 | 169 | /** 170 | * Get scope. 171 | * 172 | * @return array 173 | */ 174 | public function getScope() 175 | { 176 | return $this->scope; 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /src/Entity/RefreshTokenRepository.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Entity; 13 | 14 | use AuthBucket\OAuth2\Model\RefreshTokenManagerInterface; 15 | 16 | /** 17 | * RefreshTokenRepository. 18 | * 19 | * This class was generated by the Doctrine ORM. Add your own custom 20 | * repository methods below. 21 | */ 22 | class RefreshTokenRepository extends AbstractEntityRepository implements RefreshTokenManagerInterface 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /src/Entity/Scope.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Entity; 13 | 14 | use AuthBucket\OAuth2\Model\ScopeInterface; 15 | use Doctrine\ORM\Mapping as ORM; 16 | 17 | /** 18 | * Scope. 19 | * 20 | * @ORM\MappedSuperclass(repositoryClass="AuthBucket\Bundle\OAuth2Bundle\Entity\ScopeRepository") 21 | */ 22 | abstract class Scope implements ScopeInterface 23 | { 24 | /** 25 | * @var string 26 | * 27 | * @ORM\Column(name="scope", type="string", length=255) 28 | */ 29 | protected $scope; 30 | 31 | /** 32 | * Set scope. 33 | * 34 | * @param string $scope 35 | * 36 | * @return Scope 37 | */ 38 | public function setScope($scope) 39 | { 40 | $this->scope = $scope; 41 | 42 | return $this; 43 | } 44 | 45 | /** 46 | * Get scope. 47 | * 48 | * @return string 49 | */ 50 | public function getScope() 51 | { 52 | return $this->scope; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Entity/ScopeRepository.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Entity; 13 | 14 | use AuthBucket\OAuth2\Model\ScopeManagerInterface; 15 | 16 | /** 17 | * ScopeRepository. 18 | * 19 | * This class was generated by the Doctrine ORM. Add your own custom 20 | * repository methods below. 21 | */ 22 | class ScopeRepository extends AbstractEntityRepository implements ScopeManagerInterface 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /src/Resources/config/in_memory.yml: -------------------------------------------------------------------------------- 1 | parameters: 2 | authbucket_oauth2.model: 3 | access_token: AuthBucket\OAuth2\Model\AccessToken 4 | 5 | services: 6 | authbucket_oauth2.model_manager.factory: 7 | class: AuthBucket\OAuth2\Model\ModelManagerFactory 8 | arguments: 9 | - "%authbucket_oauth2.model%" 10 | -------------------------------------------------------------------------------- /src/Resources/config/orm.yml: -------------------------------------------------------------------------------- 1 | parameters: 2 | authbucket_oauth2.model: ~ 3 | 4 | services: 5 | authbucket_oauth2.model_manager.factory: 6 | class: AuthBucket\Bundle\OAuth2Bundle\Entity\ModelManagerFactory 7 | arguments: 8 | - "@doctrine.orm.entity_manager" 9 | - "%authbucket_oauth2.model%" 10 | -------------------------------------------------------------------------------- /src/Resources/config/routing.yml: -------------------------------------------------------------------------------- 1 | api_oauth2_authorize: 2 | path: /authorize 3 | defaults: { _controller: AuthBucketOAuth2Bundle:Authorization:index } 4 | methods: [ GET ] 5 | 6 | api_oauth2_token: 7 | path: /token 8 | defaults: { _controller: AuthBucketOAuth2Bundle:Token:index } 9 | methods: [ POST ] 10 | 11 | api_oauth2_debug: 12 | path: /debug 13 | defaults: { _controller: AuthBucketOAuth2Bundle:Debug:index } 14 | methods: [ GET|POST ] 15 | -------------------------------------------------------------------------------- /src/Resources/config/services.yml: -------------------------------------------------------------------------------- 1 | parameters: 2 | authbucket_oauth2.response_type_handler: 3 | code: AuthBucket\OAuth2\ResponseType\CodeResponseTypeHandler 4 | token: AuthBucket\OAuth2\ResponseType\TokenResponseTypeHandler 5 | 6 | authbucket_oauth2.grant_type_handler: 7 | authorization_code: AuthBucket\OAuth2\GrantType\AuthorizationCodeGrantTypeHandler 8 | client_credentials: AuthBucket\OAuth2\GrantType\ClientCredentialsGrantTypeHandler 9 | password: AuthBucket\OAuth2\GrantType\PasswordGrantTypeHandler 10 | refresh_token: AuthBucket\OAuth2\GrantType\RefreshTokenGrantTypeHandler 11 | 12 | authbucket_oauth2.token_type_handler: 13 | bearer: AuthBucket\OAuth2\TokenType\BearerTokenTypeHandler 14 | mac: AuthBucket\OAuth2\TokenType\MacTokenTypeHandler 15 | 16 | authbucket_oauth2.resource_type_handler: 17 | model: AuthBucket\OAuth2\ResourceType\ModelResourceTypeHandler 18 | debug_endpoint: AuthBucket\OAuth2\ResourceType\DebugEndpointResourceTypeHandler 19 | 20 | services: 21 | authbucket_oauth2.exception_listener: 22 | class: AuthBucket\OAuth2\Symfony\Component\EventDispatcher\ExceptionListener 23 | arguments: 24 | - "@logger" 25 | tags: 26 | - { name: kernel.event_listener, event: kernel.exception, method: onKernelException, priority: -2 } 27 | 28 | authbucket_oauth2.response_type_handler.factory: 29 | class: AuthBucket\OAuth2\ResponseType\ResponseTypeHandlerFactory 30 | arguments: 31 | - "@security.token_storage" 32 | - "@validator" 33 | - "@authbucket_oauth2.model_manager.factory" 34 | - "@authbucket_oauth2.token_type_handler.factory" 35 | - "%authbucket_oauth2.response_type_handler%" 36 | 37 | authbucket_oauth2.grant_type_handler.factory: 38 | class: AuthBucket\OAuth2\GrantType\GrantTypeHandlerFactory 39 | arguments: 40 | - "@security.token_storage" 41 | - "@security.encoder_factory" 42 | - "@validator" 43 | - "@authbucket_oauth2.model_manager.factory" 44 | - "@authbucket_oauth2.token_type_handler.factory" 45 | - ~ 46 | - "%authbucket_oauth2.grant_type_handler%" 47 | 48 | authbucket_oauth2.token_type_handler.factory: 49 | class: AuthBucket\OAuth2\TokenType\TokenTypeHandlerFactory 50 | arguments: 51 | - "@validator" 52 | - "@authbucket_oauth2.model_manager.factory" 53 | - "%authbucket_oauth2.token_type_handler%" 54 | 55 | authbucket_oauth2.resource_type_handler.factory: 56 | class: AuthBucket\OAuth2\ResourceType\ResourceTypeHandlerFactory 57 | arguments: 58 | - "@http_kernel" 59 | - "@authbucket_oauth2.model_manager.factory" 60 | - "%authbucket_oauth2.resource_type_handler%" 61 | 62 | authbucket_oauth2.authorization_controller: 63 | class: AuthBucket\OAuth2\Controller\AuthorizationController 64 | arguments: 65 | - "@validator" 66 | - "@authbucket_oauth2.response_type_handler.factory" 67 | 68 | authbucket_oauth2.token_controller: 69 | class: AuthBucket\OAuth2\Controller\TokenController 70 | arguments: 71 | - "@validator" 72 | - "@authbucket_oauth2.grant_type_handler.factory" 73 | 74 | authbucket_oauth2.debug_controller: 75 | class: AuthBucket\OAuth2\Controller\DebugController 76 | arguments: 77 | - "@security.token_storage" 78 | 79 | security.authentication.provider.token: 80 | class: AuthBucket\OAuth2\Symfony\Component\Security\Core\Authentication\Provider\TokenProvider 81 | arguments: 82 | - ~ 83 | - "@authbucket_oauth2.model_manager.factory" 84 | 85 | security.authentication.listener.token: 86 | class: AuthBucket\OAuth2\Symfony\Component\Security\Http\Firewall\TokenListener 87 | arguments: 88 | - ~ 89 | - "@security.token_storage" 90 | - "@security.authentication.manager" 91 | - "@validator" 92 | - "@logger" 93 | 94 | security.authentication.provider.resource: 95 | class: AuthBucket\OAuth2\Symfony\Component\Security\Core\Authentication\Provider\ResourceProvider 96 | arguments: 97 | - ~ 98 | - "@authbucket_oauth2.resource_type_handler.factory" 99 | - ~ 100 | - ~ 101 | - ~ 102 | 103 | security.authentication.listener.resource: 104 | class: AuthBucket\OAuth2\Symfony\Component\Security\Http\Firewall\ResourceListener 105 | arguments: 106 | - ~ 107 | - "@security.token_storage" 108 | - "@security.authentication.manager" 109 | - "@validator" 110 | - "@logger" 111 | - "@authbucket_oauth2.token_type_handler.factory" 112 | -------------------------------------------------------------------------------- /src/Resources/doc/index.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/authbucket/oauth2-symfony-bundle/ae9faa3c9237dcac711dedf471aae4a83b1168f2/src/Resources/doc/index.rst -------------------------------------------------------------------------------- /src/Resources/translations/messages.fr.xlf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Symfony2 is great 7 | J'aime Symfony2 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /tests/AutoloadTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests; 13 | 14 | /** 15 | * Test if autoload able to discover all required classes. 16 | * 17 | * @author Wong Hoi Sing Edison 18 | */ 19 | class AutoloadTest extends \PHPUnit_Framework_TestCase 20 | { 21 | public function testExceptionClassesExist() 22 | { 23 | $this->assertTrue(class_exists('AuthBucket\OAuth2\Exception\AccessDeniedException')); 24 | $this->assertTrue(class_exists('AuthBucket\OAuth2\Exception\InvalidClientException')); 25 | $this->assertTrue(class_exists('AuthBucket\OAuth2\Exception\InvalidGrantException')); 26 | $this->assertTrue(class_exists('AuthBucket\OAuth2\Exception\InvalidRequestException')); 27 | $this->assertTrue(class_exists('AuthBucket\OAuth2\Exception\InvalidScopeException')); 28 | $this->assertTrue(class_exists('AuthBucket\OAuth2\Exception\ServerErrorException')); 29 | $this->assertTrue(class_exists('AuthBucket\OAuth2\Exception\TemporarilyUnavailableException')); 30 | $this->assertTrue(class_exists('AuthBucket\OAuth2\Exception\UnauthorizedClientException')); 31 | $this->assertTrue(class_exists('AuthBucket\OAuth2\Exception\UnsupportedGrantTypeException')); 32 | $this->assertTrue(class_exists('AuthBucket\OAuth2\Exception\UnsupportedResponseTypeException')); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/Exception/AccessDeniedExceptionTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\Exception; 13 | 14 | use AuthBucket\OAuth2\Exception\AccessDeniedException; 15 | 16 | /** 17 | * Test access denied exception. 18 | * 19 | * @author Wong Hoi Sing Edison 20 | */ 21 | class AccessDeniedExceptionTest extends \PHPUnit_Framework_TestCase 22 | { 23 | /** 24 | * @expectedException \AuthBucket\OAuth2\Exception\AccessDeniedException 25 | */ 26 | public function testAccessDeniedException() 27 | { 28 | throw new AccessDeniedException(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/Exception/InvalidClientExceptionTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\Exception; 13 | 14 | use AuthBucket\OAuth2\Exception\InvalidClientException; 15 | 16 | /** 17 | * Test invalid client exception. 18 | * 19 | * @author Wong Hoi Sing Edison 20 | */ 21 | class InvalidClientExceptionTest extends \PHPUnit_Framework_TestCase 22 | { 23 | /** 24 | * @expectedException \AuthBucket\OAuth2\Exception\InvalidClientException 25 | */ 26 | public function testInvalidClientException() 27 | { 28 | throw new InvalidClientException(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/Exception/InvalidGrantExceptionTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\Exception; 13 | 14 | use AuthBucket\OAuth2\Exception\InvalidGrantException; 15 | 16 | /** 17 | * Test invalid grant exception. 18 | * 19 | * @author Wong Hoi Sing Edison 20 | */ 21 | class InvalidGrantExceptionTest extends \PHPUnit_Framework_TestCase 22 | { 23 | /** 24 | * @expectedException \AuthBucket\OAuth2\Exception\InvalidGrantException 25 | */ 26 | public function testInvalidGrantException() 27 | { 28 | throw new InvalidGrantException(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/Exception/InvalidRequestExceptionTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\Exception; 13 | 14 | use AuthBucket\OAuth2\Exception\InvalidRequestException; 15 | 16 | /** 17 | * Test invalid request exception. 18 | * 19 | * @author Wong Hoi Sing Edison 20 | */ 21 | class InvalidRequestExceptionTest extends \PHPUnit_Framework_TestCase 22 | { 23 | /** 24 | * @expectedException \AuthBucket\OAuth2\Exception\InvalidRequestException 25 | */ 26 | public function testInvalidRequestException() 27 | { 28 | throw new InvalidRequestException(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/Exception/InvalidScopeExceptionTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\Exception; 13 | 14 | use AuthBucket\OAuth2\Exception\InvalidScopeException; 15 | 16 | /** 17 | * Test invalid scope exception. 18 | * 19 | * @author Wong Hoi Sing Edison 20 | */ 21 | class InvalidScopeExceptionTest extends \PHPUnit_Framework_TestCase 22 | { 23 | /** 24 | * @expectedException \AuthBucket\OAuth2\Exception\InvalidScopeException 25 | */ 26 | public function testInvalidScopeException() 27 | { 28 | throw new InvalidScopeException(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/Exception/ServerErrorExceptionTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\Exception; 13 | 14 | use AuthBucket\OAuth2\Exception\ServerErrorException; 15 | 16 | /** 17 | * Test server error exception. 18 | * 19 | * @author Wong Hoi Sing Edison 20 | */ 21 | class ServerErrorExceptionTest extends \PHPUnit_Framework_TestCase 22 | { 23 | /** 24 | * @expectedException \AuthBucket\OAuth2\Exception\ServerErrorException 25 | */ 26 | public function testServerErrorException() 27 | { 28 | throw new ServerErrorException(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/Exception/TemporarilyUnavailableExceptionTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\Exception; 13 | 14 | use AuthBucket\OAuth2\Exception\TemporarilyUnavailableException; 15 | 16 | /** 17 | * Test temporarily unavailable exception. 18 | * 19 | * @author Wong Hoi Sing Edison 20 | */ 21 | class TemporarilyUnavailableExceptionTest extends \PHPUnit_Framework_TestCase 22 | { 23 | /** 24 | * @expectedException \AuthBucket\OAuth2\Exception\TemporarilyUnavailableException 25 | */ 26 | public function testTemporarilyUnavailableException() 27 | { 28 | throw new TemporarilyUnavailableException(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/Exception/UnauthorizedClientExceptionTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\Exception; 13 | 14 | use AuthBucket\OAuth2\Exception\UnauthorizedClientException; 15 | 16 | /** 17 | * Test unauthorized client exception. 18 | * 19 | * @author Wong Hoi Sing Edison 20 | */ 21 | class UnauthorizedClientExceptionTest extends \PHPUnit_Framework_TestCase 22 | { 23 | /** 24 | * @expectedException \AuthBucket\OAuth2\Exception\UnauthorizedClientException 25 | */ 26 | public function testUnauthorizedClientException() 27 | { 28 | throw new UnauthorizedClientException(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/Exception/UnsupportedGrantTypeExceptionTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\Exception; 13 | 14 | use AuthBucket\OAuth2\Exception\UnsupportedGrantTypeException; 15 | 16 | /** 17 | * Test unsupported grant type exception. 18 | * 19 | * @author Wong Hoi Sing Edison 20 | */ 21 | class UnsupportedGrantTypeExceptionTest extends \PHPUnit_Framework_TestCase 22 | { 23 | /** 24 | * @expectedException \AuthBucket\OAuth2\Exception\UnsupportedGrantTypeException 25 | */ 26 | public function testUnsupportedGrantTypeException() 27 | { 28 | throw new UnsupportedGrantTypeException(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/Exception/UnsupportedResponseTypeTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\Exception; 13 | 14 | use AuthBucket\OAuth2\Exception\UnsupportedResponseTypeException; 15 | 16 | /** 17 | * Test unsupported response type exception. 18 | * 19 | * @author Wong Hoi Sing Edison 20 | */ 21 | class UnsupportedResponseTypeTest extends \PHPUnit_Framework_TestCase 22 | { 23 | /** 24 | * @expectedException \AuthBucket\OAuth2\Exception\UnsupportedResponseTypeException 25 | */ 26 | public function testUnsupportedResponseTypeException() 27 | { 28 | throw new UnsupportedResponseTypeException(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/GrantType/BarGrantTypeHandler.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\GrantType; 13 | 14 | use AuthBucket\OAuth2\GrantType\GrantTypeHandlerInterface; 15 | use Symfony\Component\HttpFoundation\Request; 16 | 17 | class BarGrantTypeHandler implements GrantTypeHandlerInterface 18 | { 19 | public function handle(Request $request) 20 | { 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/GrantType/ClientCredentialsGrantTypeHandlerTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\GrantType; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Tests\WebTestCase; 15 | use Symfony\Component\HttpFoundation\Request; 16 | 17 | class ClientCredentialsGrantTypeHandlerTest extends WebTestCase 18 | { 19 | public function testErrorClientCredBadScope() 20 | { 21 | $parameters = [ 22 | 'grant_type' => 'client_credentials', 23 | 'scope' => 'badscope1', 24 | ]; 25 | $server = [ 26 | 'PHP_AUTH_USER' => 'http://democlient1.com/', 27 | 'PHP_AUTH_PW' => 'demosecret1', 28 | ]; 29 | $client = $this->createClient(); 30 | $crawler = $client->request('POST', '/api/oauth2/token', $parameters, [], $server); 31 | $this->assertSame(400, $client->getResponse()->getStatusCode()); 32 | $this->assertNotNull(json_decode($client->getResponse()->getContent())); 33 | $tokenResponse = json_decode($client->getResponse()->getContent(), true); 34 | $this->assertSame('invalid_scope', $tokenResponse['error']); 35 | } 36 | 37 | public function testErrorClientCredBadScopeFormat() 38 | { 39 | $parameters = [ 40 | 'grant_type' => 'client_credentials', 41 | 'scope' => "demoscope1\x22demoscope2\x5cdemoscope3", 42 | ]; 43 | $server = [ 44 | 'PHP_AUTH_USER' => 'http://democlient1.com/', 45 | 'PHP_AUTH_PW' => 'demosecret1', 46 | ]; 47 | $client = $this->createClient(); 48 | $crawler = $client->request('POST', '/api/oauth2/token', $parameters, [], $server); 49 | $this->assertSame(400, $client->getResponse()->getStatusCode()); 50 | $this->assertNotNull(json_decode($client->getResponse()->getContent())); 51 | $tokenResponse = json_decode($client->getResponse()->getContent(), true); 52 | $this->assertSame('invalid_request', $tokenResponse['error']); 53 | } 54 | 55 | public function testGoodClientCred() 56 | { 57 | $parameters = [ 58 | 'grant_type' => 'client_credentials', 59 | 'scope' => 'demoscope1 demoscope2 demoscope3', 60 | ]; 61 | $server = [ 62 | 'PHP_AUTH_USER' => 'http://democlient1.com/', 63 | 'PHP_AUTH_PW' => 'demosecret1', 64 | ]; 65 | $client = $this->createClient(); 66 | $crawler = $client->request('POST', '/api/oauth2/token', $parameters, [], $server); 67 | $this->assertSame(200, $client->getResponse()->getStatusCode()); 68 | $this->assertNotNull(json_decode($client->getResponse()->getContent())); 69 | } 70 | 71 | public function testGoodClientCredNoScope() 72 | { 73 | $parameters = [ 74 | 'grant_type' => 'client_credentials', 75 | ]; 76 | $server = [ 77 | 'PHP_AUTH_USER' => 'http://democlient1.com/', 78 | 'PHP_AUTH_PW' => 'demosecret1', 79 | ]; 80 | $client = $this->createClient(); 81 | $crawler = $client->request('POST', '/api/oauth2/token', $parameters, [], $server); 82 | $this->assertSame(200, $client->getResponse()->getStatusCode()); 83 | $this->assertNotNull(json_decode($client->getResponse()->getContent())); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /tests/GrantType/FooGrantTypeHandler.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\GrantType; 13 | 14 | class FooGrantTypeHandler 15 | { 16 | } 17 | -------------------------------------------------------------------------------- /tests/GrantType/GrantTypeHandlerFactoryTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\GrantType; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Tests\WebTestCase; 15 | use AuthBucket\OAuth2\GrantType\GrantTypeHandlerFactory; 16 | 17 | class GrantTypeHandlerFactoryTest extends WebTestCase 18 | { 19 | /** 20 | * @expectedException \AuthBucket\OAuth2\Exception\UnsupportedGrantTypeException 21 | */ 22 | public function testNonExistsGrantTypeHandler() 23 | { 24 | $classes = ['foo' => 'AuthBucket\\Bundle\\OAuth2Bundle\\Tests\\GrantType\\NonExistsGrantTypeHandler']; 25 | $factory = new GrantTypeHandlerFactory( 26 | $this->get('security.token_storage'), 27 | $this->get('security.encoder_factory'), 28 | $this->get('validator'), 29 | $this->get('authbucket_oauth2.model_manager.factory'), 30 | $this->get('authbucket_oauth2.token_type_handler.factory'), 31 | null, 32 | $classes 33 | ); 34 | } 35 | 36 | /** 37 | * @expectedException \AuthBucket\OAuth2\Exception\UnsupportedGrantTypeException 38 | */ 39 | public function testBadAddGrantTypeHandler() 40 | { 41 | $classes = ['foo' => 'AuthBucket\\Bundle\\OAuth2Bundle\\Tests\\GrantType\\FooGrantTypeHandler']; 42 | $factory = new GrantTypeHandlerFactory( 43 | $this->get('security.token_storage'), 44 | $this->get('security.encoder_factory'), 45 | $this->get('validator'), 46 | $this->get('authbucket_oauth2.model_manager.factory'), 47 | $this->get('authbucket_oauth2.token_type_handler.factory'), 48 | null, 49 | $classes 50 | ); 51 | } 52 | 53 | /** 54 | * @expectedException \AuthBucket\OAuth2\Exception\UnsupportedGrantTypeException 55 | */ 56 | public function testBadGetGrantTypeHandler() 57 | { 58 | $classes = ['bar' => 'AuthBucket\\Bundle\\OAuth2Bundle\\Tests\\GrantType\\BarGrantTypeHandler']; 59 | $factory = new GrantTypeHandlerFactory( 60 | $this->get('security.token_storage'), 61 | $this->get('security.encoder_factory'), 62 | $this->get('validator'), 63 | $this->get('authbucket_oauth2.model_manager.factory'), 64 | $this->get('authbucket_oauth2.token_type_handler.factory'), 65 | null, 66 | $classes 67 | ); 68 | $handler = $factory->getGrantTypeHandler('foo'); 69 | } 70 | 71 | public function testGoodGetGrantTypeHandler() 72 | { 73 | $classes = ['bar' => 'AuthBucket\\Bundle\\OAuth2Bundle\\Tests\\GrantType\\BarGrantTypeHandler']; 74 | $factory = new GrantTypeHandlerFactory( 75 | $this->get('security.token_storage'), 76 | $this->get('security.encoder_factory'), 77 | $this->get('validator'), 78 | $this->get('authbucket_oauth2.model_manager.factory'), 79 | $this->get('authbucket_oauth2.token_type_handler.factory'), 80 | null, 81 | $classes 82 | ); 83 | $handler = $factory->getGrantTypeHandler('bar'); 84 | $this->assertSame($factory->getGrantTypeHandlers(), $classes); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /tests/GrantType/RefreshTokenGrantTypeHandlerTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\GrantType; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Tests\WebTestCase; 15 | use Symfony\Component\HttpFoundation\Request; 16 | 17 | class RefreshTokenGrantTypeHandlerTest extends WebTestCase 18 | { 19 | public function testErrorRefreshTokenNoToken() 20 | { 21 | $parameters = [ 22 | 'grant_type' => 'refresh_token', 23 | 'scope' => 'demoscope1 demoscope2 demoscope3', 24 | ]; 25 | $server = [ 26 | 'PHP_AUTH_USER' => 'http://democlient1.com/', 27 | 'PHP_AUTH_PW' => 'demosecret1', 28 | ]; 29 | $client = $this->createClient(); 30 | $crawler = $client->request('POST', '/api/oauth2/token', $parameters, [], $server); 31 | $this->assertSame(400, $client->getResponse()->getStatusCode()); 32 | $this->assertNotNull(json_decode($client->getResponse()->getContent())); 33 | $tokenResponse = json_decode($client->getResponse()->getContent(), true); 34 | $this->assertSame('invalid_request', $tokenResponse['error']); 35 | } 36 | 37 | public function testErrorRefreshTokenBadScope() 38 | { 39 | $parameters = [ 40 | 'grant_type' => 'refresh_token', 41 | 'refresh_token' => '288b5ea8e75d2b24368a79ed5ed9593b', 42 | 'scope' => 'badscope1', 43 | ]; 44 | $server = [ 45 | 'PHP_AUTH_USER' => 'http://democlient3.com/', 46 | 'PHP_AUTH_PW' => 'demosecret3', 47 | ]; 48 | $client = $this->createClient(); 49 | $crawler = $client->request('POST', '/api/oauth2/token', $parameters, [], $server); 50 | $this->assertSame(400, $client->getResponse()->getStatusCode()); 51 | $this->assertNotNull(json_decode($client->getResponse()->getContent())); 52 | $tokenResponse = json_decode($client->getResponse()->getContent(), true); 53 | $this->assertSame('invalid_scope', $tokenResponse['error']); 54 | } 55 | 56 | public function testErrorRefreshTokenUnsupportedScope() 57 | { 58 | $parameters = [ 59 | 'grant_type' => 'refresh_token', 60 | 'refresh_token' => '302a7e7af27a25a6c052302d0dcac2c0', 61 | 'scope' => 'unsupportedscope', 62 | ]; 63 | $server = [ 64 | 'PHP_AUTH_USER' => 'http://democlient2.com/', 65 | 'PHP_AUTH_PW' => 'demosecret2', 66 | ]; 67 | $client = $this->createClient(); 68 | $crawler = $client->request('POST', '/api/oauth2/token', $parameters, [], $server); 69 | $this->assertSame(400, $client->getResponse()->getStatusCode()); 70 | $this->assertNotNull(json_decode($client->getResponse()->getContent())); 71 | $tokenResponse = json_decode($client->getResponse()->getContent(), true); 72 | $this->assertSame('invalid_scope', $tokenResponse['error']); 73 | } 74 | 75 | public function testErrorRefreshTokenUnauthorizedScope() 76 | { 77 | $parameters = [ 78 | 'grant_type' => 'refresh_token', 79 | 'refresh_token' => '302a7e7af27a25a6c052302d0dcac2c0', 80 | 'scope' => 'demoscope4', 81 | ]; 82 | $server = [ 83 | 'PHP_AUTH_USER' => 'http://democlient2.com/', 84 | 'PHP_AUTH_PW' => 'demosecret2', 85 | ]; 86 | $client = $this->createClient(); 87 | $crawler = $client->request('POST', '/api/oauth2/token', $parameters, [], $server); 88 | $this->assertSame(400, $client->getResponse()->getStatusCode()); 89 | $this->assertNotNull(json_decode($client->getResponse()->getContent())); 90 | $tokenResponse = json_decode($client->getResponse()->getContent(), true); 91 | $this->assertSame('invalid_scope', $tokenResponse['error']); 92 | } 93 | 94 | public function testErrorRefreshTokenBadScopeFormat() 95 | { 96 | $parameters = [ 97 | 'grant_type' => 'refresh_token', 98 | 'refresh_token' => '288b5ea8e75d2b24368a79ed5ed9593b', 99 | 'scope' => "demoscope1\x22demoscope2\x5cdemoscope3", 100 | ]; 101 | $server = [ 102 | 'PHP_AUTH_USER' => 'http://democlient3.com/', 103 | 'PHP_AUTH_PW' => 'demosecret3', 104 | ]; 105 | $client = $this->createClient(); 106 | $crawler = $client->request('POST', '/api/oauth2/token', $parameters, [], $server); 107 | $this->assertSame(400, $client->getResponse()->getStatusCode()); 108 | $this->assertNotNull(json_decode($client->getResponse()->getContent())); 109 | $tokenResponse = json_decode($client->getResponse()->getContent(), true); 110 | $this->assertSame('invalid_request', $tokenResponse['error']); 111 | } 112 | 113 | public function testExceptionRefreshTokenBadClientId() 114 | { 115 | $parameters = [ 116 | 'grant_type' => 'refresh_token', 117 | 'refresh_token' => '288b5ea8e75d2b24368a79ed5ed9593b', 118 | 'scope' => 'demoscope1 demoscope2 demoscope3', 119 | ]; 120 | $server = [ 121 | 'PHP_AUTH_USER' => 'http://democlient1.com/', 122 | 'PHP_AUTH_PW' => 'demosecret1', 123 | ]; 124 | $client = $this->createClient(); 125 | $crawler = $client->request('POST', '/api/oauth2/token', $parameters, [], $server); 126 | $this->assertSame(400, $client->getResponse()->getStatusCode()); 127 | $this->assertNotNull(json_decode($client->getResponse()->getContent())); 128 | $tokenResponse = json_decode($client->getResponse()->getContent(), true); 129 | $this->assertSame('invalid_grant', $tokenResponse['error']); 130 | } 131 | 132 | public function testExceptionRefreshTokenExpired() 133 | { 134 | $parameters = [ 135 | 'grant_type' => 'refresh_token', 136 | 'refresh_token' => '5ff43cbc27b54202c6fd8bb9c2a308ce', 137 | 'scope' => 'demoscope1', 138 | ]; 139 | $server = [ 140 | 'PHP_AUTH_USER' => 'http://democlient1.com/', 141 | 'PHP_AUTH_PW' => 'demosecret1', 142 | ]; 143 | $client = $this->createClient(); 144 | $crawler = $client->request('POST', '/api/oauth2/token', $parameters, [], $server); 145 | $this->assertSame(400, $client->getResponse()->getStatusCode()); 146 | $this->assertNotNull(json_decode($client->getResponse()->getContent())); 147 | $tokenResponse = json_decode($client->getResponse()->getContent(), true); 148 | $this->assertSame('invalid_grant', $tokenResponse['error']); 149 | } 150 | 151 | public function testGoodRefreshToken() 152 | { 153 | $parameters = [ 154 | 'grant_type' => 'refresh_token', 155 | 'refresh_token' => '288b5ea8e75d2b24368a79ed5ed9593b', 156 | 'scope' => 'demoscope1 demoscope2 demoscope3', 157 | ]; 158 | $server = [ 159 | 'PHP_AUTH_USER' => 'http://democlient3.com/', 160 | 'PHP_AUTH_PW' => 'demosecret3', 161 | ]; 162 | $client = $this->createClient(); 163 | $crawler = $client->request('POST', '/api/oauth2/token', $parameters, [], $server); 164 | $this->assertSame(200, $client->getResponse()->getStatusCode()); 165 | $this->assertNotNull(json_decode($client->getResponse()->getContent())); 166 | 167 | $parameters = [ 168 | 'grant_type' => 'refresh_token', 169 | 'refresh_token' => '288b5ea8e75d2b24368a79ed5ed9593b', 170 | ]; 171 | $server = [ 172 | 'PHP_AUTH_USER' => 'http://democlient3.com/', 173 | 'PHP_AUTH_PW' => 'demosecret3', 174 | ]; 175 | $client = $this->createClient(); 176 | $crawler = $client->request('POST', '/api/oauth2/token', $parameters, [], $server); 177 | $this->assertSame(200, $client->getResponse()->getStatusCode()); 178 | $this->assertNotNull(json_decode($client->getResponse()->getContent())); 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /tests/Model/InMemoryTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Buneld\OAuth2Bundle\Tests\Model; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Tests\WebTestCase; 15 | use Symfony\Component\Config\FileLocator; 16 | use Symfony\Component\DependencyInjection\ContainerBuilder; 17 | use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; 18 | use Symfony\Component\HttpFoundation\Request; 19 | 20 | class InMemoryTest extends WebTestCase 21 | { 22 | /** 23 | * @group legacy 24 | */ 25 | public function setUp() 26 | { 27 | parent::setUp(); 28 | 29 | $container = new ContainerBuilder(); 30 | $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../../src/Resources/config')); 31 | $loader->load('in_memory.yml'); 32 | $container->compile(); 33 | 34 | $this->set( 35 | 'authbucket_oauth2.model_manager.factory', 36 | $container->get('authbucket_oauth2.model_manager.factory') 37 | ); 38 | 39 | $accessTokenManager = $this->get('authbucket_oauth2.model_manager.factory')->getModelManager('access_token'); 40 | $className = $accessTokenManager->getClassName(); 41 | 42 | $model = new $className(); 43 | $model->setAccessToken('eeb5aa92bbb4b56373b9e0d00bc02d93') 44 | ->setTokenType('bearer') 45 | ->setClientId('http://democlient1.com/') 46 | ->setUsername('demousername1') 47 | ->setExpires(new \DateTime('+1 hours')) 48 | ->setScope([ 49 | 'demoscope1', 50 | ]); 51 | $accessTokenManager->createModel($model); 52 | 53 | $model = new $className(); 54 | $model->setAccessToken('d2b58c4c6bc0cc9fefca2d558f1221a5') 55 | ->setTokenType('bearer') 56 | ->setClientId('http://democlient1.com/') 57 | ->setUsername('demousername1') 58 | ->setExpires(new \DateTime('-1 hours')) 59 | ->setScope([ 60 | 'demoscope1', 61 | ]); 62 | $accessTokenManager->createModel($model); 63 | } 64 | 65 | public function testExceptionBadAccessToken() 66 | { 67 | $parameters = []; 68 | $server = [ 69 | 'HTTP_Authorization' => implode(' ', ['Bearer', "aaa\x19bbb\x5Cccc\x7Fddd"]), 70 | ]; 71 | $client = $this->createClient(); 72 | $crawler = $client->request('GET', '/api/resource/debug_endpoint', $parameters, [], $server); 73 | $resourceResponse = json_decode($client->getResponse()->getContent(), true); 74 | $this->assertSame('invalid_request', $resourceResponse['error']); 75 | } 76 | 77 | public function testExceptionNotExistsAccessToken() 78 | { 79 | $parameters = []; 80 | $server = [ 81 | 'HTTP_Authorization' => implode(' ', ['Bearer', 'abcd']), 82 | ]; 83 | $client = $this->createClient(); 84 | $crawler = $client->request('GET', '/api/resource/debug_endpoint', $parameters, [], $server); 85 | $resourceResponse = json_decode($client->getResponse()->getContent(), true); 86 | $this->assertSame('invalid_request', $resourceResponse['error']); 87 | } 88 | 89 | public function testExceptionExpiredAccessToken() 90 | { 91 | $parameters = []; 92 | $server = [ 93 | 'HTTP_Authorization' => implode(' ', ['Bearer', 'd2b58c4c6bc0cc9fefca2d558f1221a5']), 94 | ]; 95 | $client = $this->createClient(); 96 | $crawler = $client->request('GET', '/api/resource/debug_endpoint', $parameters, [], $server); 97 | $resourceResponse = json_decode($client->getResponse()->getContent(), true); 98 | $this->assertSame('invalid_request', $resourceResponse['error']); 99 | } 100 | 101 | public function testExceptionInvalidParameter() 102 | { 103 | $parameters = []; 104 | $server = [ 105 | 'HTTP_Authorization' => implode(' ', ['Bearer', 'eeb5aa92bbb4b56373b9e0d00bc02d93']), 106 | ]; 107 | $client = $this->createClient(); 108 | $crawler = $client->request('GET', '/api/resource/debug_endpoint/invalid_options', $parameters, [], $server); 109 | $resourceResponse = json_decode($client->getResponse()->getContent(), true); 110 | $this->assertSame('server_error', $resourceResponse['error']); 111 | } 112 | 113 | public function testGoodAccessToken() 114 | { 115 | $parameters = []; 116 | $server = [ 117 | 'HTTP_Authorization' => implode(' ', ['Bearer', 'eeb5aa92bbb4b56373b9e0d00bc02d93']), 118 | ]; 119 | $client = $this->createClient(); 120 | $crawler = $client->request('GET', '/api/resource/debug_endpoint', $parameters, [], $server); 121 | $resourceResponse = json_decode($client->getResponse()->getContent(), true); 122 | $this->assertSame('demousername1', $resourceResponse['username']); 123 | } 124 | 125 | public function testGoodAccessTokenCached() 126 | { 127 | $parameters = []; 128 | $server = [ 129 | 'HTTP_Authorization' => implode(' ', ['Bearer', 'eeb5aa92bbb4b56373b9e0d00bc02d93']), 130 | ]; 131 | $client = $this->createClient(); 132 | $crawler = $client->request('GET', '/api/resource/debug_endpoint/cache', $parameters, [], $server); 133 | $resourceResponse = json_decode($client->getResponse()->getContent(), true); 134 | $this->assertSame('demousername1', $resourceResponse['username']); 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /tests/ResourceType/BarResourceTypeHandler.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\ResourceType; 13 | 14 | use AuthBucket\OAuth2\ResourceType\ResourceTypeHandlerInterface; 15 | 16 | class BarResourceTypeHandler implements ResourceTypeHandlerInterface 17 | { 18 | public function handle( 19 | $accessToken, 20 | array $options = [] 21 | ) { 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/ResourceType/DebugEndpointResourceTypeHandlerTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\ResourceType; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Tests\WebTestCase; 15 | use Symfony\Component\HttpFoundation\Request; 16 | 17 | class DebugEndpointResourceTypeHandlerTest extends WebTestCase 18 | { 19 | public function testExceptionBadAccessToken() 20 | { 21 | $parameters = []; 22 | $server = [ 23 | 'HTTP_Authorization' => implode(' ', ['Bearer', "aaa\x19bbb\x5Cccc\x7Fddd"]), 24 | ]; 25 | $client = $this->createClient(); 26 | $crawler = $client->request('GET', '/api/resource/debug_endpoint', $parameters, [], $server); 27 | $resourceResponse = json_decode($client->getResponse()->getContent(), true); 28 | $this->assertSame('invalid_request', $resourceResponse['error']); 29 | } 30 | 31 | public function testExceptionNotExistsAccessToken() 32 | { 33 | $parameters = []; 34 | $server = [ 35 | 'HTTP_Authorization' => implode(' ', ['Bearer', 'abcd']), 36 | ]; 37 | $client = $this->createClient(); 38 | $crawler = $client->request('GET', '/api/resource/debug_endpoint', $parameters, [], $server); 39 | $resourceResponse = json_decode($client->getResponse()->getContent(), true); 40 | $this->assertSame('invalid_request', $resourceResponse['error']); 41 | } 42 | 43 | public function testExceptionExpiredAccessToken() 44 | { 45 | $parameters = []; 46 | $server = [ 47 | 'HTTP_Authorization' => implode(' ', ['Bearer', 'd2b58c4c6bc0cc9fefca2d558f1221a5']), 48 | ]; 49 | $client = $this->createClient(); 50 | $crawler = $client->request('GET', '/api/resource/debug_endpoint', $parameters, [], $server); 51 | $resourceResponse = json_decode($client->getResponse()->getContent(), true); 52 | $this->assertSame('invalid_request', $resourceResponse['error']); 53 | } 54 | 55 | public function testExceptionInvalidParameter() 56 | { 57 | $parameters = []; 58 | $server = [ 59 | 'HTTP_Authorization' => implode(' ', ['Bearer', 'eeb5aa92bbb4b56373b9e0d00bc02d93']), 60 | ]; 61 | $client = $this->createClient(); 62 | $crawler = $client->request('GET', '/api/resource/debug_endpoint/invalid_options', $parameters, [], $server); 63 | $resourceResponse = json_decode($client->getResponse()->getContent(), true); 64 | $this->assertSame('server_error', $resourceResponse['error']); 65 | } 66 | 67 | public function testGoodAccessToken() 68 | { 69 | $parameters = []; 70 | $server = [ 71 | 'HTTP_Authorization' => implode(' ', ['Bearer', 'eeb5aa92bbb4b56373b9e0d00bc02d93']), 72 | ]; 73 | $client = $this->createClient(); 74 | $crawler = $client->request('GET', '/api/resource/debug_endpoint', $parameters, [], $server); 75 | $resourceResponse = json_decode($client->getResponse()->getContent(), true); 76 | $this->assertSame('demousername1', $resourceResponse['username']); 77 | } 78 | 79 | public function testGoodAccessTokenCached() 80 | { 81 | $parameters = []; 82 | $server = [ 83 | 'HTTP_Authorization' => implode(' ', ['Bearer', 'eeb5aa92bbb4b56373b9e0d00bc02d93']), 84 | ]; 85 | $client = $this->createClient(); 86 | $crawler = $client->request('GET', '/api/resource/debug_endpoint/cache', $parameters, [], $server); 87 | $resourceResponse = json_decode($client->getResponse()->getContent(), true); 88 | $this->assertSame('demousername1', $resourceResponse['username']); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /tests/ResourceType/FooResourceTypeHandler.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\ResourceType; 13 | 14 | class FooResourceTypeHandler 15 | { 16 | } 17 | -------------------------------------------------------------------------------- /tests/ResourceType/ModelResourceTypeHandlerTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\ResourceType; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Tests\WebTestCase; 15 | use Symfony\Component\HttpFoundation\Request; 16 | 17 | class ModelResourceTypeHandlerTest extends WebTestCase 18 | { 19 | public function testExceptionNotExistsAccessToken() 20 | { 21 | $parameters = []; 22 | $server = [ 23 | 'HTTP_Authorization' => implode(' ', ['Bearer', 'abcd']), 24 | ]; 25 | $client = $this->createClient(); 26 | $crawler = $client->request('GET', '/api/resource/model', $parameters, [], $server); 27 | $resourceResponse = json_decode($client->getResponse()->getContent(), true); 28 | $this->assertSame('invalid_request', $resourceResponse['error']); 29 | } 30 | 31 | public function testExceptionExpiredAccessToken() 32 | { 33 | $parameters = []; 34 | $server = [ 35 | 'HTTP_Authorization' => implode(' ', ['Bearer', 'd2b58c4c6bc0cc9fefca2d558f1221a5']), 36 | ]; 37 | $client = $this->createClient(); 38 | $crawler = $client->request('GET', '/api/resource/model', $parameters, [], $server); 39 | $resourceResponse = json_decode($client->getResponse()->getContent(), true); 40 | $this->assertSame('invalid_request', $resourceResponse['error']); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/ResourceType/ResourceTypeHandlerFactoryTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\ResourceType; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Tests\WebTestCase; 15 | use AuthBucket\OAuth2\ResourceType\ResourceTypeHandlerFactory; 16 | 17 | class ResourceTypeHandlerFactoryTest extends WebTestCase 18 | { 19 | /** 20 | * @expectedException \AuthBucket\OAuth2\Exception\ServerErrorException 21 | */ 22 | public function testNonExistsResourceTypeHandler() 23 | { 24 | $classes = ['foo' => 'AuthBucket\\Bundle\\OAuth2Bundle\\Tests\\ResourceType\\NonExistsResourceTypeHandler']; 25 | $factory = new ResourceTypeHandlerFactory( 26 | $this->get('http_kernel'), 27 | $this->get('authbucket_oauth2.model_manager.factory'), 28 | $classes 29 | ); 30 | } 31 | 32 | /** 33 | * @expectedException \AuthBucket\OAuth2\Exception\ServerErrorException 34 | */ 35 | public function testBadAddResourceTypeHandler() 36 | { 37 | $classes = ['foo' => 'AuthBucket\\Bundle\\OAuth2Bundle\\Tests\\ResourceType\\FooResourceTypeHandler']; 38 | $factory = new ResourceTypeHandlerFactory( 39 | $this->get('http_kernel'), 40 | $this->get('authbucket_oauth2.model_manager.factory'), 41 | $classes 42 | ); 43 | } 44 | 45 | /** 46 | * @expectedException \AuthBucket\OAuth2\Exception\ServerErrorException 47 | */ 48 | public function testBadGetResourceTypeHandler() 49 | { 50 | $classes = ['bar' => 'AuthBucket\\Bundle\\OAuth2Bundle\\Tests\\ResourceType\\BarResourceTypeHandler']; 51 | $factory = new ResourceTypeHandlerFactory( 52 | $this->get('http_kernel'), 53 | $this->get('authbucket_oauth2.model_manager.factory'), 54 | $classes 55 | ); 56 | $handler = $factory->getResourceTypeHandler('foo'); 57 | } 58 | 59 | public function testGoodGetResourceTypeHandler() 60 | { 61 | $classes = ['bar' => 'AuthBucket\\Bundle\\OAuth2Bundle\\Tests\\ResourceType\\BarResourceTypeHandler']; 62 | $factory = new ResourceTypeHandlerFactory( 63 | $this->get('http_kernel'), 64 | $this->get('authbucket_oauth2.model_manager.factory'), 65 | $classes 66 | ); 67 | $handler = $factory->getResourceTypeHandler('bar'); 68 | $this->assertSame($factory->getResourceTypeHandlers(), $classes); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /tests/ResponseType/BarResponseTypeHandler.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\ResponseType; 13 | 14 | use AuthBucket\OAuth2\ResponseType\ResponseTypeHandlerInterface; 15 | use Symfony\Component\HttpFoundation\Request; 16 | 17 | class BarResponseTypeHandler implements ResponseTypeHandlerInterface 18 | { 19 | public function handle(Request $request) 20 | { 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/ResponseType/FooResponseTypeHandler.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\ResponseType; 13 | 14 | class FooResponseTypeHandler 15 | { 16 | } 17 | -------------------------------------------------------------------------------- /tests/ResponseType/ResponseTypeHandlerFactoryTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\ResponseType; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Tests\WebTestCase; 15 | use AuthBucket\OAuth2\ResponseType\ResponseTypeHandlerFactory; 16 | 17 | class ResponseTypeHandlerFactoryTest extends WebTestCase 18 | { 19 | /** 20 | * @expectedException \AuthBucket\OAuth2\Exception\UnsupportedResponseTypeException 21 | */ 22 | public function testNonExistsResponseTypeHandler() 23 | { 24 | $classes = ['foo' => 'AuthBucket\\Bundle\\OAuth2Bundle\\Tests\\ResponseType\\NonExistsResponseTypeHandler']; 25 | $factory = new ResponseTypeHandlerFactory( 26 | $this->get('security.token_storage'), 27 | $this->get('validator'), 28 | $this->get('authbucket_oauth2.model_manager.factory'), 29 | $this->get('authbucket_oauth2.token_type_handler.factory'), 30 | $classes 31 | ); 32 | } 33 | 34 | /** 35 | * @expectedException \AuthBucket\OAuth2\Exception\UnsupportedResponseTypeException 36 | */ 37 | public function testBadAddResponseTypeHandler() 38 | { 39 | $classes = ['foo' => 'AuthBucket\\Bundle\\OAuth2Bundle\\Tests\\ResponseType\\FooResponseTypeHandler']; 40 | $factory = new ResponseTypeHandlerFactory( 41 | $this->get('security.token_storage'), 42 | $this->get('validator'), 43 | $this->get('authbucket_oauth2.model_manager.factory'), 44 | $this->get('authbucket_oauth2.token_type_handler.factory'), 45 | $classes 46 | ); 47 | } 48 | 49 | /** 50 | * @expectedException \AuthBucket\OAuth2\Exception\UnsupportedResponseTypeException 51 | */ 52 | public function testBadGetResponseTypeHandler() 53 | { 54 | $classes = ['bar' => 'AuthBucket\\Bundle\\OAuth2Bundle\\Tests\\ResponseType\\BarResponseTypeHandler']; 55 | $factory = new ResponseTypeHandlerFactory( 56 | $this->get('security.token_storage'), 57 | $this->get('validator'), 58 | $this->get('authbucket_oauth2.model_manager.factory'), 59 | $this->get('authbucket_oauth2.token_type_handler.factory'), 60 | $classes 61 | ); 62 | $handler = $factory->getResponseTypeHandler('foo'); 63 | } 64 | 65 | public function testGoodGetResponseTypeHandler() 66 | { 67 | $classes = ['bar' => 'AuthBucket\\Bundle\\OAuth2Bundle\\Tests\\ResponseType\\BarResponseTypeHandler']; 68 | $factory = new ResponseTypeHandlerFactory( 69 | $this->get('security.token_storage'), 70 | $this->get('validator'), 71 | $this->get('authbucket_oauth2.model_manager.factory'), 72 | $this->get('authbucket_oauth2.token_type_handler.factory'), 73 | $classes 74 | ); 75 | $handler = $factory->getResponseTypeHandler('bar'); 76 | $this->assertSame($factory->getResponseTypeHandlers(), $classes); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /tests/Security/Authentication/Provider/ResourceProviderTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\Security\Authentication\Provider; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Tests\WebTestCase; 15 | use Symfony\Component\HttpFoundation\Request; 16 | 17 | class ResourceProviderTest extends WebTestCase 18 | { 19 | public function testNonCompatibileScope() 20 | { 21 | $parameters = []; 22 | $server = [ 23 | 'HTTP_Authorization' => implode(' ', ['Bearer', 'bcc105b66698a64ed23c87b967885289']), 24 | ]; 25 | $client = $this->createClient(); 26 | $crawler = $client->request('GET', '/api/resource/model', $parameters, [], $server); 27 | $resourceResponse = json_decode($client->getResponse()->getContent(), true); 28 | $this->assertSame('invalid_scope', $resourceResponse['error']); 29 | } 30 | 31 | public function testEnoughScope() 32 | { 33 | $parameters = []; 34 | $server = [ 35 | 'HTTP_Authorization' => implode(' ', ['Bearer', 'eeb5aa92bbb4b56373b9e0d00bc02d93']), 36 | ]; 37 | $client = $this->createClient(); 38 | $crawler = $client->request('GET', '/api/resource/model', $parameters, [], $server); 39 | $resourceResponse = json_decode($client->getResponse()->getContent(), true); 40 | $this->assertSame('demousername1', $resourceResponse['username']); 41 | } 42 | 43 | public function testMoreScope() 44 | { 45 | $parameters = []; 46 | $server = [ 47 | 'HTTP_Authorization' => implode(' ', ['Bearer', 'ba2e8d1f54ed3e3d96935796576f1a06']), 48 | ]; 49 | $client = $this->createClient(); 50 | $crawler = $client->request('GET', '/api/resource/model', $parameters, [], $server); 51 | $resourceResponse = json_decode($client->getResponse()->getContent(), true); 52 | $this->assertSame('demousername1', $resourceResponse['username']); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /tests/TestBundle/Controller/DefaultController.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Controller; 13 | 14 | use Doctrine\Common\DataFixtures\Executor\ORMExecutor; 15 | use Doctrine\Common\DataFixtures\Loader; 16 | use Doctrine\Common\DataFixtures\Purger\ORMPurger; 17 | use Doctrine\Common\Persistence\PersistentObject; 18 | use Doctrine\ORM\Tools\SchemaTool; 19 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; 20 | use Symfony\Component\HttpFoundation\Request; 21 | 22 | class DefaultController extends Controller 23 | { 24 | public function indexAction(Request $request) 25 | { 26 | return $this->render('TestBundle::index.html.twig'); 27 | } 28 | 29 | public function gettingStartedIndexAction(Request $request) 30 | { 31 | return $this->render('TestBundle:getting-started:index.html.twig'); 32 | } 33 | 34 | public function adminRefreshDatabaseAction(Request $request) 35 | { 36 | $conn = $this->get('database_connection'); 37 | $em = $this->get('doctrine')->getManager(); 38 | 39 | $params = $conn->getParams(); 40 | $name = isset($params['path']) ? $params['path'] : (isset($params['dbname']) ? $params['dbname'] : false); 41 | 42 | try { 43 | $conn->getSchemaManager()->dropDatabase($name); 44 | $conn->getSchemaManager()->createDatabase($name); 45 | $conn->close(); 46 | } catch (\Exception $e) { 47 | return 1; 48 | } 49 | 50 | $classes = []; 51 | foreach ($this->container->getParameter('authbucket_oauth2.model') as $class) { 52 | $classes[] = $em->getClassMetadata($class); 53 | } 54 | 55 | PersistentObject::setObjectManager($em); 56 | $tool = new SchemaTool($em); 57 | $tool->dropSchema($classes); 58 | $tool->createSchema($classes); 59 | 60 | $purger = new ORMPurger(); 61 | $executor = new ORMExecutor($em, $purger); 62 | 63 | $loader = new Loader(); 64 | $loader->loadFromDirectory(__DIR__.'/../DataFixtures/ORM'); 65 | $executor->execute($loader->getFixtures()); 66 | 67 | return $this->redirect($this->get('router')->generate('index')); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/TestBundle/DataFixtures/ORM/AccessTokenFixture.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\DataFixtures\ORM; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Entity\AccessToken; 15 | use Doctrine\Common\DataFixtures\FixtureInterface; 16 | use Doctrine\Common\Persistence\ObjectManager; 17 | 18 | class AccessTokenFixture implements FixtureInterface 19 | { 20 | public function load(ObjectManager $manager) 21 | { 22 | $model = new AccessToken(); 23 | $model->setAccessToken('18cdaa6481c0d5f323351ea1029fc065') 24 | ->setTokenType('bearer') 25 | ->setClientId('6b44c21ef7bc8ca7380bb5b8276b3f97') 26 | ->setUsername('') 27 | ->setExpires(new \DateTime('+10 years')) 28 | ->setScope([]); 29 | $manager->persist($model); 30 | 31 | $model = new AccessToken(); 32 | $model->setAccessToken('eeb5aa92bbb4b56373b9e0d00bc02d93') 33 | ->setTokenType('bearer') 34 | ->setClientId('http://democlient1.com/') 35 | ->setUsername('demousername1') 36 | ->setExpires(new \DateTime('+10 years')) 37 | ->setScope([ 38 | 'demoscope1', 39 | ]); 40 | $manager->persist($model); 41 | 42 | $model = new AccessToken(); 43 | $model->setAccessToken('d2b58c4c6bc0cc9fefca2d558f1221a5') 44 | ->setTokenType('bearer') 45 | ->setClientId('http://democlient1.com/') 46 | ->setUsername('demousername1') 47 | ->setExpires(new \DateTime('-1 hours')) 48 | ->setScope([ 49 | 'demoscope1', 50 | ]); 51 | $manager->persist($model); 52 | 53 | $model = new AccessToken(); 54 | $model->setAccessToken('ba2e8d1f54ed3e3d96935796576f1a06') 55 | ->setTokenType('bearer') 56 | ->setClientId('http://democlient1.com/') 57 | ->setUsername('demousername1') 58 | ->setExpires(new \DateTime('+1 hours')) 59 | ->setScope([ 60 | 'demoscope1', 61 | 'demoscope2', 62 | ]); 63 | $manager->persist($model); 64 | 65 | $model = new AccessToken(); 66 | $model->setAccessToken('bcc105b66698a64ed23c87b967885289') 67 | ->setTokenType('bearer') 68 | ->setClientId('http://democlient1.com/') 69 | ->setUsername('demousername1') 70 | ->setExpires(new \DateTime('+1 hours')) 71 | ->setScope([ 72 | 'demoscope3', 73 | ]); 74 | $manager->persist($model); 75 | 76 | $manager->flush(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /tests/TestBundle/DataFixtures/ORM/AuthorizeFixture.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\DataFixtures\ORM; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Entity\Authorize; 15 | use Doctrine\Common\DataFixtures\FixtureInterface; 16 | use Doctrine\Common\Persistence\ObjectManager; 17 | 18 | class AuthorizeFixture implements FixtureInterface 19 | { 20 | public function load(ObjectManager $manager) 21 | { 22 | $model = new Authorize(); 23 | $model->setClientId('51b2d34c3a661b5e111a694dfcb4b248') 24 | ->setUsername('demousername1') 25 | ->setScope([ 26 | 'demoscope1', 27 | 'demoscope2', 28 | 'demoscope3', 29 | ]); 30 | $manager->persist($model); 31 | 32 | $model = new Authorize(); 33 | $model->setClientId('6b44c21ef7bc8ca7380bb5b8276b3f97') 34 | ->setUsername('demousername1') 35 | ->setScope([ 36 | 'demoscope1', 37 | 'demoscope2', 38 | 'demoscope3', 39 | 'demoscope4', 40 | ]); 41 | $manager->persist($model); 42 | 43 | $model = new Authorize(); 44 | $model->setClientId('authorization_code_grant') 45 | ->setUsername('demousername1') 46 | ->setScope([ 47 | 'demoscope1', 48 | ]); 49 | $manager->persist($model); 50 | 51 | $model = new Authorize(); 52 | $model->setClientId('implicit_grant') 53 | ->setUsername('demousername1') 54 | ->setScope([ 55 | 'demoscope1', 56 | ]); 57 | $manager->persist($model); 58 | 59 | $model = new Authorize(); 60 | $model->setClientId('resource_owner_password_credentials_grant') 61 | ->setUsername('demousername1') 62 | ->setScope([ 63 | 'demoscope1', 64 | ]); 65 | $manager->persist($model); 66 | 67 | $model = new Authorize(); 68 | $model->setClientId('client_credentials_grant') 69 | ->setUsername('') 70 | ->setScope([ 71 | 'demoscope1', 72 | ]); 73 | $manager->persist($model); 74 | 75 | $model = new Authorize(); 76 | $model->setClientId('http://democlient1.com/') 77 | ->setUsername('demousername1') 78 | ->setScope([ 79 | 'demoscope1', 80 | ]); 81 | $manager->persist($model); 82 | 83 | $model = new Authorize(); 84 | $model->setClientId('http://democlient2.com/') 85 | ->setUsername('demousername2') 86 | ->setScope([ 87 | 'demoscope1', 88 | 'demoscope2', 89 | ]); 90 | $manager->persist($model); 91 | 92 | $model = new Authorize(); 93 | $model->setClientId('http://democlient3.com/') 94 | ->setUsername('demousername3') 95 | ->setScope([ 96 | 'demoscope1', 97 | 'demoscope2', 98 | 'demoscope3', 99 | ]); 100 | $manager->persist($model); 101 | 102 | $model = new Authorize(); 103 | $model->setClientId('http://democlient1.com/') 104 | ->setUsername('') 105 | ->setScope([ 106 | 'demoscope1', 107 | 'demoscope2', 108 | 'demoscope3', 109 | ]); 110 | $manager->persist($model); 111 | 112 | $manager->flush(); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /tests/TestBundle/DataFixtures/ORM/ClientFixture.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\DataFixtures\ORM; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Entity\Client; 15 | use Doctrine\Common\DataFixtures\FixtureInterface; 16 | use Doctrine\Common\Persistence\ObjectManager; 17 | use Symfony\Component\HttpFoundation\Request; 18 | 19 | class ClientFixture implements FixtureInterface 20 | { 21 | public function load(ObjectManager $manager) 22 | { 23 | $request = Request::createFromGlobals(); 24 | if (!$request->getUri()) { 25 | $request = Request::create('http://127.0.0.1:8000'); 26 | } 27 | 28 | $model = new Client(); 29 | $model->setClientId('51b2d34c3a661b5e111a694dfcb4b248') 30 | ->setClientSecret('237ed57f218b41d07db6757afec3a41c') 31 | ->setRedirectUri('http://oauthconnector.demo.drupal.authbucket.com/oauth/authorized2/1'); 32 | $manager->persist($model); 33 | 34 | $model = new Client(); 35 | $model->setClientId('6b44c21ef7bc8ca7380bb5b8276b3f97') 36 | ->setClientSecret('54fe25c871b3ee81d037b6b22bed84b2') 37 | ->setRedirectUri('http://localhost'); 38 | $manager->persist($model); 39 | 40 | $model = new Client(); 41 | $model->setClientId('authorization_code_grant') 42 | ->setClientSecret('uoce8AeP') 43 | ->setRedirectUri($request->getUriForPath('/demo/response_type/code')); 44 | $manager->persist($model); 45 | 46 | $model = new Client(); 47 | $model->setClientId('implicit_grant') 48 | ->setClientSecret('Ac1chee1') 49 | ->setRedirectUri($request->getUriForPath('/demo/response_type/token')); 50 | $manager->persist($model); 51 | 52 | $model = new Client(); 53 | $model->setClientId('resource_owner_password_credentials_grant') 54 | ->setClientSecret('Eevahph6') 55 | ->setRedirectUri($request->getUriForPath('/demo/grant_type/password')); 56 | $manager->persist($model); 57 | 58 | $model = new Client(); 59 | $model->setClientId('client_credentials_grant') 60 | ->setClientSecret('yib6aiFe') 61 | ->setRedirectUri($request->getUriForPath('/demo/grant_type/client_credentials')); 62 | $manager->persist($model); 63 | 64 | $model = new Client(); 65 | $model->setClientId('http://democlient1.com/') 66 | ->setClientSecret('demosecret1') 67 | ->setRedirectUri('http://democlient1.com/redirect_uri'); 68 | $manager->persist($model); 69 | 70 | $model = new Client(); 71 | $model->setClientId('http://democlient2.com/') 72 | ->setClientSecret('demosecret2') 73 | ->setRedirectUri('http://democlient2.com/redirect_uri'); 74 | $manager->persist($model); 75 | 76 | $model = new Client(); 77 | $model->setClientId('http://democlient3.com/') 78 | ->setClientSecret('demosecret3') 79 | ->setRedirectUri('http://democlient3.com/redirect_uri'); 80 | $manager->persist($model); 81 | 82 | $model = new Client(); 83 | $model->setClientId('http://democlient4.com/') 84 | ->setClientSecret('demosecret4') 85 | ->setRedirectUri(''); 86 | $manager->persist($model); 87 | 88 | $manager->flush(); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /tests/TestBundle/DataFixtures/ORM/CodeFixture.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\DataFixtures\ORM; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Entity\Code; 15 | use Doctrine\Common\DataFixtures\FixtureInterface; 16 | use Doctrine\Common\Persistence\ObjectManager; 17 | 18 | class CodeFixture implements FixtureInterface 19 | { 20 | public function load(ObjectManager $manager) 21 | { 22 | $model = new Code(); 23 | $model->setCode('f0c68d250bcc729eb780a235371a9a55') 24 | ->setClientId('http://democlient2.com/') 25 | ->setUsername('demousername2') 26 | ->setRedirectUri('http://democlient2.com/redirect_uri') 27 | ->setExpires(new \DateTime('+10 minutes')) 28 | ->setScope([ 29 | 'demoscope1', 30 | 'demoscope2', 31 | ]); 32 | $manager->persist($model); 33 | 34 | $model = new Code(); 35 | $model->setCode('1e5aa97ddaf4b0228dfb4223010d4417') 36 | ->setClientId('http://democlient1.com/') 37 | ->setUsername('demousername1') 38 | ->setRedirectUri('http://democlient1.com/redirect_uri') 39 | ->setExpires(new \DateTime('-10 minutes')) 40 | ->setScope([ 41 | 'demoscope1', 42 | ]); 43 | $manager->persist($model); 44 | 45 | $model = new Code(); 46 | $model->setCode('08fb55e26c84f8cb060b7803bc177af8') 47 | ->setClientId('http://democlient4.com/') 48 | ->setUsername('demousername4') 49 | ->setRedirectUri('http://democlient4.com/redirect_uri') 50 | ->setExpires(new \DateTime('+10 minutes')) 51 | ->setScope([ 52 | 'demoscope1', 53 | ]); 54 | $manager->persist($model); 55 | 56 | $manager->flush(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tests/TestBundle/DataFixtures/ORM/RefreshTokenFixture.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\DataFixtures\ORM; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Entity\RefreshToken; 15 | use Doctrine\Common\DataFixtures\FixtureInterface; 16 | use Doctrine\Common\Persistence\ObjectManager; 17 | 18 | class RefreshTokenFixture implements FixtureInterface 19 | { 20 | public function load(ObjectManager $manager) 21 | { 22 | $model = new RefreshToken(); 23 | $model->setRefreshToken('5ff43cbc27b54202c6fd8bb9c2a308ce') 24 | ->setClientId('http://democlient1.com/') 25 | ->setUsername('demousername1') 26 | ->setExpires(new \DateTime('-1 days')) 27 | ->setScope([ 28 | 'demoscope1', 29 | ]); 30 | $manager->persist($model); 31 | 32 | $model = new RefreshToken(); 33 | $model->setRefreshToken('302a7e7af27a25a6c052302d0dcac2c0') 34 | ->setClientId('http://democlient2.com/') 35 | ->setUsername('demousername2') 36 | ->setExpires(new \DateTime('+1 days')) 37 | ->setScope([ 38 | 'unsupportedscope', 39 | 'demoscope4', 40 | ]); 41 | $manager->persist($model); 42 | 43 | $model = new RefreshToken(); 44 | $model->setRefreshToken('288b5ea8e75d2b24368a79ed5ed9593b') 45 | ->setClientId('http://democlient3.com/') 46 | ->setUsername('demousername3') 47 | ->setExpires(new \DateTime('+1 days')) 48 | ->setScope([ 49 | 'demoscope1', 50 | 'demoscope2', 51 | 'demoscope3', 52 | ]); 53 | $manager->persist($model); 54 | 55 | $manager->flush(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /tests/TestBundle/DataFixtures/ORM/ScopeFixture.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\DataFixtures\ORM; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Entity\Scope; 15 | use Doctrine\Common\DataFixtures\FixtureInterface; 16 | use Doctrine\Common\Persistence\ObjectManager; 17 | 18 | class ScopeFixture implements FixtureInterface 19 | { 20 | public function load(ObjectManager $manager) 21 | { 22 | $model = new Scope(); 23 | $model->setScope('demoscope1'); 24 | $manager->persist($model); 25 | 26 | $model = new Scope(); 27 | $model->setScope('demoscope2'); 28 | $manager->persist($model); 29 | 30 | $model = new Scope(); 31 | $model->setScope('demoscope3'); 32 | $manager->persist($model); 33 | 34 | $model = new Scope(); 35 | $model->setScope('demoscope4'); 36 | $manager->persist($model); 37 | 38 | $manager->flush(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/TestBundle/DataFixtures/ORM/UserFixture.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\DataFixtures\ORM; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Entity\User; 15 | use Doctrine\Common\DataFixtures\FixtureInterface; 16 | use Doctrine\Common\Persistence\ObjectManager; 17 | 18 | class UserFixture implements FixtureInterface 19 | { 20 | public function load(ObjectManager $manager) 21 | { 22 | $model = new User(); 23 | $model->setUsername('demousername1') 24 | ->setPassword('demopassword1') 25 | ->setRoles([ 26 | 'ROLE_USER', 27 | ]); 28 | $manager->persist($model); 29 | 30 | $model = new User(); 31 | $model->setUsername('demousername2') 32 | ->setPassword('demopassword2') 33 | ->setRoles([ 34 | 'ROLE_USER', 35 | ]); 36 | $manager->persist($model); 37 | 38 | $model = new User(); 39 | $model->setUsername('demousername3') 40 | ->setPassword('demopassword3') 41 | ->setRoles([ 42 | 'ROLE_USER', 43 | ]); 44 | $manager->persist($model); 45 | 46 | $manager->flush(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /tests/TestBundle/Entity/AccessToken.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Entity; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Entity\AccessToken as AbstractAccessToken; 15 | use Doctrine\ORM\Mapping as ORM; 16 | 17 | /** 18 | * AccessToken. 19 | * 20 | * @ORM\Table(name="authbucket_oauth2_access_token") 21 | * @ORM\Entity(repositoryClass="AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Entity\AccessTokenRepository") 22 | */ 23 | class AccessToken extends AbstractAccessToken 24 | { 25 | /** 26 | * @var int 27 | * 28 | * @ORM\Column(name="id", type="integer") 29 | * @ORM\Id 30 | * @ORM\GeneratedValue(strategy="AUTO") 31 | */ 32 | protected $id; 33 | 34 | /** 35 | * Get id. 36 | * 37 | * @return int 38 | */ 39 | public function getId() 40 | { 41 | return $this->id; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/TestBundle/Entity/AccessTokenRepository.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Entity; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Entity\AccessTokenRepository as AbstractAccessTokenRepository; 15 | 16 | /** 17 | * AccessTokenRepository. 18 | * 19 | * This class was generated by the Doctrine ORM. Add your own custom 20 | * repository methods below. 21 | */ 22 | class AccessTokenRepository extends AbstractAccessTokenRepository 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /tests/TestBundle/Entity/Authorize.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Entity; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Entity\Authorize as AbstractAuthorize; 15 | use Doctrine\ORM\Mapping as ORM; 16 | 17 | /** 18 | * Authorize. 19 | * 20 | * @ORM\Table(name="authbucket_oauth2_authorize") 21 | * @ORM\Entity(repositoryClass="AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Entity\AuthorizeRepository") 22 | */ 23 | class Authorize extends AbstractAuthorize 24 | { 25 | /** 26 | * @var int 27 | * 28 | * @ORM\Column(name="id", type="integer") 29 | * @ORM\Id 30 | * @ORM\GeneratedValue(strategy="AUTO") 31 | */ 32 | protected $id; 33 | 34 | /** 35 | * Get id. 36 | * 37 | * @return int 38 | */ 39 | public function getId() 40 | { 41 | return $this->id; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/TestBundle/Entity/AuthorizeRepository.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Entity; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Entity\AuthorizeRepository as AbstractAuthorizeRepository; 15 | 16 | /** 17 | * AuthorizeRepository. 18 | * 19 | * This class was generated by the Doctrine ORM. Add your own custom 20 | * repository methods below. 21 | */ 22 | class AuthorizeRepository extends AbstractAuthorizeRepository 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /tests/TestBundle/Entity/Client.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Entity; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Entity\Client as AbstractClient; 15 | use Doctrine\ORM\Mapping as ORM; 16 | 17 | /** 18 | * Client. 19 | * 20 | * @ORM\Table(name="authbucket_oauth2_client") 21 | * @ORM\Entity(repositoryClass="AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Entity\ClientRepository") 22 | */ 23 | class Client extends AbstractClient 24 | { 25 | /** 26 | * @var int 27 | * 28 | * @ORM\Column(name="id", type="integer") 29 | * @ORM\Id 30 | * @ORM\GeneratedValue(strategy="AUTO") 31 | */ 32 | protected $id; 33 | 34 | /** 35 | * Get id. 36 | * 37 | * @return int 38 | */ 39 | public function getId() 40 | { 41 | return $this->id; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/TestBundle/Entity/ClientRepository.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Entity; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Entity\ClientRepository as AbstractClientRepository; 15 | 16 | /** 17 | * ClientRepository. 18 | * 19 | * This class was generated by the Doctrine ORM. Add your own custom 20 | * repository methods below. 21 | */ 22 | class ClientRepository extends AbstractClientRepository 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /tests/TestBundle/Entity/Code.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Entity; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Entity\Code as AbstractCode; 15 | use Doctrine\ORM\Mapping as ORM; 16 | 17 | /** 18 | * Code. 19 | * 20 | * @ORM\Table(name="authbucket_oauth2_code") 21 | * @ORM\Entity(repositoryClass="AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Entity\CodeRepository") 22 | */ 23 | class Code extends AbstractCode 24 | { 25 | /** 26 | * @var int 27 | * 28 | * @ORM\Column(name="id", type="integer") 29 | * @ORM\Id 30 | * @ORM\GeneratedValue(strategy="AUTO") 31 | */ 32 | protected $id; 33 | 34 | /** 35 | * Get id. 36 | * 37 | * @return int 38 | */ 39 | public function getId() 40 | { 41 | return $this->id; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/TestBundle/Entity/CodeRepository.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Entity; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Entity\CodeRepository as AbstractCodeRepository; 15 | 16 | /** 17 | * CodeRepository. 18 | * 19 | * This class was generated by the Doctrine ORM. Add your own custom 20 | * repository methods below. 21 | */ 22 | class CodeRepository extends AbstractCodeRepository 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /tests/TestBundle/Entity/RefreshToken.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Entity; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Entity\RefreshToken as AbstractRefreshToken; 15 | use Doctrine\ORM\Mapping as ORM; 16 | 17 | /** 18 | * RefreshToken. 19 | * 20 | * @ORM\Table(name="authbucket_oauth2_refresh_token") 21 | * @ORM\Entity(repositoryClass="AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Entity\RefreshTokenRepository") 22 | */ 23 | class RefreshToken extends AbstractRefreshToken 24 | { 25 | /** 26 | * @var int 27 | * 28 | * @ORM\Column(name="id", type="integer") 29 | * @ORM\Id 30 | * @ORM\GeneratedValue(strategy="AUTO") 31 | */ 32 | protected $id; 33 | 34 | /** 35 | * Get id. 36 | * 37 | * @return int 38 | */ 39 | public function getId() 40 | { 41 | return $this->id; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/TestBundle/Entity/RefreshTokenRepository.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Entity; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Entity\RefreshTokenRepository as AbstractRefreshTokenRepository; 15 | 16 | /** 17 | * RefreshTokenRepository. 18 | * 19 | * This class was generated by the Doctrine ORM. Add your own custom 20 | * repository methods below. 21 | */ 22 | class RefreshTokenRepository extends AbstractRefreshTokenRepository 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /tests/TestBundle/Entity/Scope.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Entity; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Entity\Scope as AbstractScope; 15 | use Doctrine\ORM\Mapping as ORM; 16 | 17 | /** 18 | * Scope. 19 | * 20 | * @ORM\Table(name="authbucket_oauth2_scope") 21 | * @ORM\Entity(repositoryClass="AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Entity\ScopeRepository") 22 | */ 23 | class Scope extends AbstractScope 24 | { 25 | /** 26 | * @var int 27 | * 28 | * @ORM\Column(name="id", type="integer") 29 | * @ORM\Id 30 | * @ORM\GeneratedValue(strategy="AUTO") 31 | */ 32 | protected $id; 33 | 34 | /** 35 | * Get id. 36 | * 37 | * @return int 38 | */ 39 | public function getId() 40 | { 41 | return $this->id; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/TestBundle/Entity/ScopeRepository.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Entity; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Entity\ScopeRepository as AbstractScopeRepository; 15 | 16 | /** 17 | * ScopeRepository. 18 | * 19 | * This class was generated by the Doctrine ORM. Add your own custom 20 | * repository methods below. 21 | */ 22 | class ScopeRepository extends AbstractScopeRepository 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /tests/TestBundle/Entity/User.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Entity; 13 | 14 | use AuthBucket\OAuth2\Model\ModelInterface; 15 | use Doctrine\ORM\Mapping as ORM; 16 | use Symfony\Component\Security\Core\User\UserInterface; 17 | 18 | /** 19 | * User. 20 | * 21 | * @ORM\Table(name="authbucket_oauth2_user") 22 | * @ORM\Entity(repositoryClass="AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Entity\UserRepository") 23 | */ 24 | class User implements ModelInterface, UserInterface 25 | { 26 | /** 27 | * @var int 28 | * 29 | * @ORM\Column(name="id", type="integer") 30 | * @ORM\Id 31 | * @ORM\GeneratedValue(strategy="AUTO") 32 | */ 33 | protected $id; 34 | 35 | /** 36 | * @var string 37 | * 38 | * @ORM\Column(name="username", type="string", length=255) 39 | */ 40 | protected $username; 41 | 42 | /** 43 | * @var string 44 | * 45 | * @ORM\Column(name="password", type="string", length=255) 46 | */ 47 | protected $password; 48 | 49 | /** 50 | * @var array 51 | * 52 | * @ORM\Column(name="roles", type="array") 53 | */ 54 | protected $roles; 55 | 56 | /** 57 | * Get id. 58 | * 59 | * @return int 60 | */ 61 | public function getId() 62 | { 63 | return $this->id; 64 | } 65 | 66 | /** 67 | * Set username. 68 | * 69 | * @param string $username 70 | * 71 | * @return User 72 | */ 73 | public function setUsername($username) 74 | { 75 | $this->username = $username; 76 | 77 | return $this; 78 | } 79 | 80 | /** 81 | * Get username. 82 | * 83 | * @return string 84 | */ 85 | public function getUsername() 86 | { 87 | return $this->username; 88 | } 89 | 90 | /** 91 | * Set password. 92 | * 93 | * @param string $password 94 | * 95 | * @return User 96 | */ 97 | public function setPassword($password) 98 | { 99 | $this->password = $password; 100 | 101 | return $this; 102 | } 103 | 104 | /** 105 | * Get password. 106 | * 107 | * @return string 108 | */ 109 | public function getPassword() 110 | { 111 | return $this->password; 112 | } 113 | 114 | /** 115 | * Set roles. 116 | * 117 | * @param array $roles 118 | * 119 | * @return User 120 | */ 121 | public function setRoles($roles) 122 | { 123 | $this->roles = $roles; 124 | 125 | return $this; 126 | } 127 | 128 | /** 129 | * Get roles. 130 | * 131 | * @return array 132 | */ 133 | public function getRoles() 134 | { 135 | return $this->roles; 136 | } 137 | 138 | public function getSalt() 139 | { 140 | } 141 | 142 | public function eraseCredentials() 143 | { 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /tests/TestBundle/Entity/UserRepository.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle\Entity; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Entity\AbstractEntityRepository; 15 | use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface; 16 | use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; 17 | use Symfony\Component\Security\Core\User\UserInterface; 18 | 19 | /** 20 | * UserRepository. 21 | * 22 | * This class was generated by the Doctrine ORM. Add your own custom 23 | * repository methods below. 24 | */ 25 | class UserRepository extends AbstractEntityRepository implements UserLoaderInterface 26 | { 27 | public function createUser() 28 | { 29 | $class = $this->getClassName(); 30 | 31 | return new $class(); 32 | } 33 | 34 | public function deleteUser(UserInterface $user) 35 | { 36 | $this->getEntityManager()->remove($user); 37 | $this->getEntityManager()->flush(); 38 | } 39 | 40 | public function reloadUser(UserInterface $user) 41 | { 42 | $this->getEntityManager()->refresh($user); 43 | } 44 | 45 | public function updateUser(UserInterface $user) 46 | { 47 | $this->getEntityManager()->persist($user); 48 | $this->getEntityManager()->flush(); 49 | } 50 | 51 | public function loadUserByUsername($username) 52 | { 53 | $user = $this->findOneBy([ 54 | 'username' => $username, 55 | ]); 56 | if ($user === null) { 57 | throw new UsernameNotFoundException(); 58 | } 59 | 60 | return $user; 61 | } 62 | 63 | public function refreshUser(UserInterface $user) 64 | { 65 | return $this->find($user->getId()); 66 | } 67 | 68 | public function supportsClass($class) 69 | { 70 | return $this->getEntityName() === $class 71 | || is_subclass_of($class, $this->getEntityName()); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /tests/TestBundle/Resources/config/routing.yml: -------------------------------------------------------------------------------- 1 | index: 2 | path: / 3 | defaults: { _controller:TestBundle:Default:index } 4 | methods: [ GET ] 5 | 6 | admin_refresh_database: 7 | path: /admin/refresh_database 8 | defaults: { _controller:TestBundle:Default:adminRefreshDatabase } 9 | methods: [ GET ] 10 | 11 | getting-started: 12 | path: /getting-started 13 | defaults: { _controller: TestBundle:Default:gettingStartedIndex } 14 | methods: [ GET ] 15 | 16 | demo: 17 | path: /demo 18 | defaults: { _controller: TestBundle:Demo:index } 19 | methods: [ GET ] 20 | 21 | demo_login: 22 | path: /demo/login 23 | defaults: { _controller: TestBundle:Demo:login } 24 | methods: [ GET ] 25 | 26 | demo_authorize: 27 | path: /demo/authorize 28 | defaults: { _controller: TestBundle:Demo:authorize } 29 | methods: [ GET|POST ] 30 | 31 | demo_authorize_login_check: 32 | path: /demo/authorize/login_check 33 | methods: [ GET|POST ] 34 | 35 | demo_authorize_logout: 36 | path: /demo/authorize/logout 37 | methods: [ GET ] 38 | 39 | demo_request_code: 40 | path: /demo/request/code 41 | defaults: { _controller: TestBundle:Demo:requestCode } 42 | methods: [ GET ] 43 | 44 | demo_request_token: 45 | path: /demo/request/token 46 | defaults: { _controller: TestBundle:Demo:requestToken } 47 | methods: [ GET ] 48 | 49 | demo_response_type_code: 50 | path: /demo/response_type/code 51 | defaults: { _controller: TestBundle:Demo:responseTypeCode } 52 | methods: [ GET ] 53 | 54 | demo_response_type_token: 55 | path: /demo/response_type/token 56 | defaults: { _controller: TestBundle:Demo:responseTypeToken } 57 | methods: [ GET ] 58 | 59 | demo_grant_type_authorization_code: 60 | path: /demo/grant_type/authorization_code 61 | defaults: { _controller: TestBundle:Demo:grantTypeAuthorizationCode } 62 | methods: [ GET ] 63 | 64 | demo_grant_type_password: 65 | path: /demo/grant_type/password 66 | defaults: { _controller: TestBundle:Demo:grantTypePassword } 67 | methods: [ GET ] 68 | 69 | demo_grant_type_client_credentials: 70 | path: /demo/grant_type/client_credentials 71 | defaults: { _controller: TestBundle:Demo:grantTypeClientCredentials } 72 | methods: [ GET ] 73 | 74 | demo_grant_type_refresh_token: 75 | path: /demo/grant_type/refresh_token 76 | defaults: { _controller: TestBundle:Demo:grantTypeRefreshToken } 77 | methods: [ GET ] 78 | 79 | demo_resource_type_model: 80 | path: /demo/resource_type/model 81 | defaults: { _controller: TestBundle:Demo:resourceTypeModel } 82 | methods: [ GET ] 83 | 84 | demo_resource_type_debug_endpoint: 85 | path: /demo/resource_type/debug_endpoint 86 | defaults: { _controller: TestBundle:Demo:resourceTypeDebugEndpoint } 87 | methods: [ GET ] 88 | 89 | api_resource_model: 90 | path: /api/resource/model 91 | defaults: { _controller: AuthBucketOAuth2Bundle:Debug:index } 92 | methods: [ GET|POST ] 93 | 94 | api_resource_debug_endpoint: 95 | path: /api/resource/debug_endpoint 96 | defaults: { _controller: AuthBucketOAuth2Bundle:Debug:index } 97 | methods: [ GET|POST ] 98 | 99 | api_resource_debug_endpoint_cache: 100 | path: /api/resource/debug_endpoint/cache 101 | defaults: { _controller: AuthBucketOAuth2Bundle:Debug:index } 102 | methods: [ GET|POST ] 103 | 104 | api_resource_debug_endpoint_invalid_options: 105 | path: /api/resource/debug_endpoint/invalid_options 106 | defaults: { _controller: AuthBucketOAuth2Bundle:Debug:index } 107 | methods: [ GET|POST ] 108 | -------------------------------------------------------------------------------- /tests/TestBundle/Resources/views/demo/authorize.html.twig: -------------------------------------------------------------------------------- 1 | {% extends 'TestBundle::html.html.twig' %} 2 | 3 | {% set head_title = 'Authorization Endpoint | AuthBucket\\Bundle\\OAuth2Bundle' %} 4 | 5 | {% block page %} 6 |
7 |
8 |
9 |

Authorization Endpoint

10 |
11 |

To request an access token, the client obtains authorization from the resource owner.

12 | 13 |
14 | 15 | 16 |

{{ username }}, {{ client_id }} would like permission to access your account:

17 |
    18 | {% for scope in scopes %} 19 |
  • {{ scope }}
  • 20 | {% endfor %} 21 |
22 |
23 | {{ form_widget(form) }} 24 |
25 | 26 |
27 |
28 |

Return

29 |

Logout

30 | 31 | 32 | {{ dump(authorization_request) }} 33 |
34 |
35 |
36 | {% endblock %} 37 | -------------------------------------------------------------------------------- /tests/TestBundle/Resources/views/demo/grant_type/authorization_code.html.twig: -------------------------------------------------------------------------------- 1 | {% extends 'TestBundle::html.html.twig' %} 2 | 3 | {% set head_title = 'Token Endpoint | AuthBucket\\Bundle\\OAuth2Bundle' %} 4 | 5 | {% block page %} 6 |
7 |
8 |
9 |

Token Endpoint (grant_type = authorization_code)

10 |
11 |

The client makes a request to the token endpoint by sending the following parameters using the "application/x-www-form-urlencoded" format per Appendix B with a character encoding of UTF-8 in the HTTP request entity-body:

12 | 13 |
14 |

Debug with Local Resource

15 |

Debug with Remote Resource

16 |

Refreshing an Access Token

17 |

Return

18 |

Logout

19 | 20 | 21 | {{ dump(access_token_response) }} 22 | 23 | 24 | {{ dump(access_token_request) }} 25 |
26 |
27 |
28 | {% endblock %} 29 | -------------------------------------------------------------------------------- /tests/TestBundle/Resources/views/demo/grant_type/client_credentials.html.twig: -------------------------------------------------------------------------------- 1 | {% extends 'TestBundle::html.html.twig' %} 2 | 3 | {% set head_title = 'Token Endpoint | AuthBucket\\Bundle\\OAuth2Bundle' %} 4 | 5 | {% block page %} 6 |
7 |
8 |
9 |

Token Endpoint (grant_type = client_credentials)

10 |
11 |

The client makes a request to the token endpoint by adding the following parameters using the "application/x-www-form-urlencoded" format per Appendix B with a character encoding of UTF-8 in the HTTP request entity-body:

12 | 13 |
14 |

Debug with Local Resource

15 |

Debug with Remote Resource

16 |

Refreshing an Access Token

17 |

Return

18 |

Logout

19 | 20 | 21 | {{ dump(access_token_response) }} 22 | 23 | 24 | {{ dump(access_token_request) }} 25 |
26 |
27 |
28 | {% endblock %} 29 | -------------------------------------------------------------------------------- /tests/TestBundle/Resources/views/demo/grant_type/password.html.twig: -------------------------------------------------------------------------------- 1 | {% extends 'TestBundle::html.html.twig' %} 2 | 3 | {% set head_title = 'Token Endpoint | AuthBucket\\Bundle\\OAuth2Bundle' %} 4 | 5 | {% block page %} 6 |
7 |
8 |
9 |

Token Endpoint (grant_type = password)

10 |
11 |

The client makes a request to the token endpoint by adding the following parameters using the "application/x-www-form-urlencoded" format per Appendix B with a character encoding of UTF-8 in the HTTP request entity-body:

12 | 13 |
14 |

Debug with Local Resource

15 |

Debug with Remote Resource

16 |

Refreshing an Access Token

17 |

Return

18 |

Logout

19 | 20 | 21 | {{ dump(access_token_response) }} 22 | 23 | 24 | {{ dump(access_token_request) }} 25 |
26 |
27 |
28 | {% endblock %} 29 | -------------------------------------------------------------------------------- /tests/TestBundle/Resources/views/demo/grant_type/refresh_token.html.twig: -------------------------------------------------------------------------------- 1 | {% extends 'TestBundle::html.html.twig' %} 2 | 3 | {% set head_title = 'Token Endpoint | AuthBucket\\Bundle\\OAuth2Bundle' %} 4 | 5 | {% block page %} 6 |
7 |
8 |
9 |

Token Endpoint (grant_type = refresh_token)

10 |
11 |

If the authorization server issued a refresh token to the client, the client makes a refresh request to the token endpoint by adding the following parameters using the "application/x-www-form-urlencoded" format per Appendix B with a character encoding of UTF-8 in the HTTP request entity-body:

12 | 13 |
14 |

Debug with Local Resource

15 |

Debug with Remote Resource

16 |

Refreshing an Access Token

17 |

Return

18 |

Logout

19 | 20 | 21 | {{ dump(access_token_response) }} 22 | 23 | 24 | {{ dump(access_token_request) }} 25 |
26 |
27 |
28 | {% endblock %} 29 | -------------------------------------------------------------------------------- /tests/TestBundle/Resources/views/demo/index.html.twig: -------------------------------------------------------------------------------- 1 | {% extends 'TestBundle::html.html.twig' %} 2 | 3 | {% set head_title = 'Demo | AuthBucket\\Bundle\\OAuth2Bundle' %} 4 | 5 | {% block page %} 6 |
7 |
8 |
9 |

Demo

10 |

Here we demos some of the basic OAuth2.0 Workflows. Corresponding request and response raw debug message will show in a step-by-step, page-by-page style. Read though routing.yml and DemoController.php to see how we implement it.

11 | 12 | 13 |
14 |

The authorization code grant type is used to obtain both access tokens and refresh tokens and is optimized for confidential clients.

15 | 16 |
17 |

Authorization Request

18 | 19 | 20 |
21 |

The implicit grant type is used to obtain access tokens (it does not support the issuance of refresh tokens) and is optimized for public clients known to operate a particular redirection URI. These clients are typically implemented in a browser using a scripting language such as JavaScript.

22 | 23 |
24 |

Authorization Request

25 | 26 | 27 |
28 |

The resource owner password credentials grant type is suitable in cases where the resource owner has a trust relationship with the client, such as the device operating system or a highly privileged application.

29 | 30 |
31 |

Access Token Request

32 | 33 | 34 |
35 |

The client can request an access token using only its client credentials (or other supported means of authentication) when the client is requesting access to the protected resources under its control, or those of another resource owner that have been previously arranged with the authorization server (the method of which is beyond the scope of this specification).

36 | 37 |
38 |

Access Token Request

39 |
40 |
41 |
42 | {% endblock %} 43 | -------------------------------------------------------------------------------- /tests/TestBundle/Resources/views/demo/login.html.twig: -------------------------------------------------------------------------------- 1 | {% extends 'TestBundle::html.html.twig' %} 2 | 3 | {% set head_title = 'Form-based Authentication | AuthBucket\\Bundle\\OAuth2Bundle' %} 4 | 5 | {% block page %} 6 |
7 |
8 |
9 |

Form-based Authentication

10 |
11 |

The authorization server MUST first verify the identity of the resource owner.

12 | 13 |
14 | 15 | 16 |
17 | {% if error is not empty %} 18 | 22 | {% endif %} 23 |
24 | 25 | 26 |
27 |
28 | 29 | 30 |
31 |
32 | 35 |
36 |
37 | 38 |
39 |
40 |

Return

41 |
42 |
43 |
44 | {% endblock %} 45 | -------------------------------------------------------------------------------- /tests/TestBundle/Resources/views/demo/resource_type/debug_endpoint.html.twig: -------------------------------------------------------------------------------- 1 | {% extends 'TestBundle::html.html.twig' %} 2 | 3 | {% set head_title = 'Resource Endpoint | AuthBucket\\Bundle\\OAuth2Bundle' %} 4 | 5 | {% block page %} 6 |
7 |
8 |
9 |

Resource Endpoint (resource_type = debug_endpoint)

10 |
11 |

The client accesses protected resources by presenting the access token to the resource server.

12 | 13 |
14 |

Return

15 |

Logout

16 | 17 | 18 | {{ dump(resource_response) }} 19 | 20 | 21 | {{ dump(resource_request) }} 22 |
23 |
24 |
25 | {% endblock %} 26 | -------------------------------------------------------------------------------- /tests/TestBundle/Resources/views/demo/resource_type/model.html.twig: -------------------------------------------------------------------------------- 1 | {% extends 'TestBundle::html.html.twig' %} 2 | 3 | {% set head_title = 'Resource Endpoint | AuthBucket\\Bundle\\OAuth2Bundle' %} 4 | 5 | {% block page %} 6 |
7 |
8 |
9 |

Resource Endpoint (resource_type = model)

10 |
11 |

The client accesses protected resources by presenting the access token to the resource server.

12 | 13 |
14 |

Return

15 |

Logout

16 | 17 | 18 | {{ dump(resource_response) }} 19 | 20 | 21 | {{ dump(resource_request) }} 22 |
23 |
24 |
25 | {% endblock %} 26 | -------------------------------------------------------------------------------- /tests/TestBundle/Resources/views/demo/response_type/code.html.twig: -------------------------------------------------------------------------------- 1 | {% extends 'TestBundle::html.html.twig' %} 2 | 3 | {% set head_title = 'Authorization Endpoint | AuthBucket\\Bundle\\OAuth2Bundle' %} 4 | 5 | {% block page %} 6 |
7 |
8 |
9 |

Authorization Endpoint (response_type = code)

10 |
11 |

The client directs the resource owner to the constructed URI using an HTTP redirection response, or by other means available to it via the user-agent.

12 | 13 |
14 |

Access Token Request

15 |

Return

16 |

Logout

17 | 18 | 19 | {{ dump(authorization_response) }} 20 |
21 |
22 |
23 | {% endblock %} 24 | -------------------------------------------------------------------------------- /tests/TestBundle/Resources/views/demo/response_type/token.html.twig: -------------------------------------------------------------------------------- 1 | {% extends 'TestBundle::html.html.twig' %} 2 | 3 | {% set head_title = 'Authorization Endpoint | AuthBucket\\Bundle\\OAuth2Bundle' %} 4 | 5 | {% block page %} 6 |
7 |
8 |
9 |

Authorization Endpoint (response_type = token)

10 |
11 |

The client directs the resource owner to the constructed URI using an HTTP redirection response, or by other means available to it via the user-agent.

12 | 13 |
14 |

Debug with Local Resource

15 |

Debug with Remote Resource

16 |

Return

17 |

Logout

18 | 19 | 20 | {{ dump(access_token_response) }} 21 |
22 |
23 |
24 | {% endblock %} 25 | -------------------------------------------------------------------------------- /tests/TestBundle/Resources/views/getting-started/index.html.twig: -------------------------------------------------------------------------------- 1 | {% extends 'TestBundle::html.html.twig' %} 2 | 3 | {% set head_title = 'Authorization Server | AuthBucket\\Bundle\\OAuth2Bundle' %} 4 | 5 | {% block page %} 6 |
7 |
8 |
9 |

Authorization Server

10 |
11 |

The server issuing access tokens to the client after successfully authenticating the resource owner and obtaining authorization.

12 | 13 |
14 |

Authorization server's endpoints usually without GUI, but just RESTful API interface. Read though routing.yml to see how we implement it.

15 | 16 | 17 |
18 |

The authorization process utilizes two authorization server endpoints (HTTP resources):

19 | 20 |
21 | 22 |

Authorization Endpoint (/api/oauth2/authorize and /demo/authorize)

23 |
24 |

The authorization endpoint is used to interact with the resource owner and obtain an authorization grant.

25 | 26 |
27 |

Authorization endpoint (HTTP Basic Authentication and Form-based Authentication) are protected by Symfony's SecurityBundle in this example. Read though security.yml to see how we implement it.

28 |

Direct browser access is possible, authentication request will therefore triggered, and able to login with following testing account:

29 |
    30 |
  • Username: demousername1
  • 31 |
  • Password: demopassword1
  • 32 |
33 |

After successful login, by default if access this endpoint without addition parameters, an error message {"error":"invalid_request"} should be shown in JSON format.

34 | 35 |

Token Endpoint (/api/oauth2/token)

36 |
37 |

The token endpoint is used by the client to obtain an access token by presenting its authorization grant or refresh token.

38 | 39 |
40 |

Token endpoint is protected by OAuth2Bundle's AuthBucketOAuth2Bundle in this example. Read though security.yml to see how we implement it.

41 |

By default this endpoint shouldn't access by browser directly with GET, else an error message {"error":"invalid_request"} should be show in JSON format.

42 |

For debug purpose, may consider send out POST request to this endpoint by HttpRequester.

43 | 44 | 45 |

Following endpoints are excluded from RFC6749, but live implementation should consider it.

46 | 47 |

Form-based Authentication (/oauth2/login)

48 |

Form-based Authentication implemented by Symfony's SecurityBundle in this example. Read though routing.yml and login.html.twig for more information.

49 |

This is used for protect above Authorization Endpoints.

50 | 51 |

Debug Endpoint (/api/oauth2/debug)

52 |

Debug Endpoint clone the idea of Facebook's Debug API Endpoint, return raw information of corresponding access_token provided. Read though security.yml and routing.yml for more information.

53 |

When working with an access token, you may need to check what information is associated with it, such as its user or expiry. To use this endpoint, you can issue a GET/POST request, e.g.:

54 |
GET /api/oauth2/debug?access_token={access_token} HTTP/1.1
55 | Host: server.example.com
56 |
    57 |
  • access_token: the access token you want to get information about
  • 58 |
59 |

The response of the API call is a JSON array containing a map of fields. For example:

60 |
{
61 |     "access_token": "5dc0bdbb2f66a842cb46a02b6d559131",
62 |     "client_id": "authorization_code_grant",
63 |     "expires": 1404641243,
64 |     "scope": [
65 |         "demoscope1"
66 |     ],
67 |     "token_type": "bearer",
68 |     "username": "demousername1"
69 | }
70 |

Remote Resource Server may also utilize this debug endpoint to verfiy the supplied access token.

71 |
72 |
73 |
74 | {% endblock %} 75 | -------------------------------------------------------------------------------- /tests/TestBundle/Resources/views/head.html.twig: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/TestBundle/Resources/views/html.html.twig: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {% block head %} 5 | {% embed 'TestBundle::head.html.twig' %}{% endembed %} 6 | {% endblock %} 7 | 8 | {{ head_title }} 9 | 10 | {% block styles %} 11 | {% embed 'TestBundle::styles.html.twig' %}{% endembed %} 12 | {% endblock %} 13 | 14 | {% block scripts %} 15 | {% embed 'TestBundle::scripts.html.twig' %}{% endembed %} 16 | {% endblock %} 17 | 18 | 19 | {% block page_top %} 20 | {% embed 'TestBundle::page_top.html.twig' %}{% endembed %} 21 | {% endblock %} 22 | 23 | {% block page %} 24 | {% embed 'TestBundle::page.html.twig' %}{% endembed %} 25 | {% endblock %} 26 | 27 | {% block page_bottom %} 28 | {% embed 'TestBundle::page_bottom.html.twig' %}{% endembed %} 29 | {% endblock %} 30 | 31 | 32 | -------------------------------------------------------------------------------- /tests/TestBundle/Resources/views/page.html.twig: -------------------------------------------------------------------------------- 1 |
2 |
3 | 8 |
9 | {% block main %}{% endblock %} 10 |
11 |
12 |
13 | -------------------------------------------------------------------------------- /tests/TestBundle/Resources/views/page_bottom.html.twig: -------------------------------------------------------------------------------- 1 | 27 | 28 | 29 | 36 | 37 | 38 | 46 | -------------------------------------------------------------------------------- /tests/TestBundle/Resources/views/page_top.html.twig: -------------------------------------------------------------------------------- 1 | Fork me on GitHub 2 | 3 |
4 | 26 |
27 | -------------------------------------------------------------------------------- /tests/TestBundle/Resources/views/scripts.html.twig: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/TestBundle/Resources/views/styles.html.twig: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/TestBundle/TestBundle.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TestBundle; 13 | 14 | use Symfony\Component\DependencyInjection\ContainerBuilder; 15 | use Symfony\Component\HttpKernel\Bundle\Bundle; 16 | 17 | class TestBundle extends Bundle 18 | { 19 | public function build(ContainerBuilder $container) 20 | { 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/TokenType/BarModelManagerFactory.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TokenType; 13 | 14 | use AuthBucket\OAuth2\Model\ModelManagerFactoryInterface; 15 | 16 | class BarModelManagerFactory implements ModelManagerFactoryInterface 17 | { 18 | public function getModelManager($type) 19 | { 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/TokenType/BarTokenTypeHandler.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TokenType; 13 | 14 | use AuthBucket\OAuth2\TokenType\TokenTypeHandlerInterface; 15 | use Symfony\Component\HttpFoundation\Request; 16 | 17 | class BarTokenTypeHandler implements TokenTypeHandlerInterface 18 | { 19 | public function getAccessToken(Request $request) 20 | { 21 | } 22 | 23 | public function createAccessToken( 24 | $clientId, 25 | $username = '', 26 | $scope = [], 27 | $state = null, 28 | $withRefreshToken = true 29 | ) { 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/TokenType/BearerTokenTypeHandlerTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TokenType; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Tests\WebTestCase; 15 | use Symfony\Component\HttpFoundation\Request; 16 | 17 | class BearerTokenTypeHandlerTest extends WebTestCase 18 | { 19 | public function testExceptionNoToken() 20 | { 21 | $parameters = []; 22 | $server = []; 23 | $client = $this->createClient(); 24 | $crawler = $client->request('GET', '/api/oauth2/debug', $parameters, [], $server); 25 | $this->assertSame(400, $client->getResponse()->getStatusCode()); 26 | $this->assertNotNull(json_decode($client->getResponse()->getContent())); 27 | $tokenResponse = json_decode($client->getResponse()->getContent(), true); 28 | $this->assertSame('invalid_request', $tokenResponse['error']); 29 | } 30 | 31 | public function testExceptionDuplicateToken() 32 | { 33 | $parameters = [ 34 | 'access_token' => 'eeb5aa92bbb4b56373b9e0d00bc02d93', 35 | ]; 36 | $server = [ 37 | 'HTTP_Authorization' => 'Bearer eeb5aa92bbb4b56373b9e0d00bc02d93', 38 | ]; 39 | $client = $this->createClient(); 40 | $crawler = $client->request('GET', '/api/oauth2/debug', $parameters, [], $server); 41 | $this->assertSame(400, $client->getResponse()->getStatusCode()); 42 | $this->assertNotNull(json_decode($client->getResponse()->getContent())); 43 | $tokenResponse = json_decode($client->getResponse()->getContent(), true); 44 | $this->assertSame('invalid_request', $tokenResponse['error']); 45 | } 46 | 47 | public function testAuthorizationHeader() 48 | { 49 | $parameters = []; 50 | $server = [ 51 | 'HTTP_Authorization' => 'Bearer eeb5aa92bbb4b56373b9e0d00bc02d93', 52 | ]; 53 | $client = $this->createClient(); 54 | $crawler = $client->request('GET', '/api/oauth2/debug', $parameters, [], $server); 55 | $resourceResponse = json_decode($client->getResponse()->getContent(), true); 56 | $this->assertSame('demousername1', $resourceResponse['username']); 57 | 58 | $parameters = []; 59 | $server = [ 60 | 'HTTP_Authorization' => 'Bearer eeb5aa92bbb4b56373b9e0d00bc02d93', 61 | ]; 62 | $client = $this->createClient(); 63 | $crawler = $client->request('POST', '/api/oauth2/debug', $parameters, [], $server); 64 | $resourceResponse = json_decode($client->getResponse()->getContent(), true); 65 | $this->assertSame('demousername1', $resourceResponse['username']); 66 | } 67 | 68 | public function testGet() 69 | { 70 | $parameters = [ 71 | 'access_token' => 'eeb5aa92bbb4b56373b9e0d00bc02d93', 72 | ]; 73 | $server = []; 74 | $client = $this->createClient(); 75 | $crawler = $client->request('GET', '/api/oauth2/debug', $parameters, [], $server); 76 | $resourceResponse = json_decode($client->getResponse()->getContent(), true); 77 | $this->assertSame('demousername1', $resourceResponse['username']); 78 | } 79 | 80 | public function testPost() 81 | { 82 | $parameters = [ 83 | 'access_token' => 'eeb5aa92bbb4b56373b9e0d00bc02d93', 84 | ]; 85 | $server = []; 86 | $client = $this->createClient(); 87 | $crawler = $client->request('POST', '/api/oauth2/debug', $parameters, [], $server); 88 | $resourceResponse = json_decode($client->getResponse()->getContent(), true); 89 | $this->assertSame('demousername1', $resourceResponse['username']); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /tests/TokenType/FooModelManagerFactory.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TokenType; 13 | 14 | class FooModelManagerFactory 15 | { 16 | } 17 | -------------------------------------------------------------------------------- /tests/TokenType/FooTokenTypeHandler.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TokenType; 13 | 14 | class FooTokenTypeHandler 15 | { 16 | } 17 | -------------------------------------------------------------------------------- /tests/TokenType/MacTokenTypeHandlerTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TokenType; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Tests\WebTestCase; 15 | use AuthBucket\OAuth2\TokenType\MacTokenTypeHandler; 16 | use Symfony\Component\HttpFoundation\Request; 17 | 18 | class MacTokenTypeHandlerTest extends WebTestCase 19 | { 20 | /** 21 | * @expectedException \AuthBucket\OAuth2\Exception\TemporarilyUnavailableException 22 | */ 23 | public function testExceptionGetAccessToken() 24 | { 25 | $request = new Request(); 26 | $handler = new MacTokenTypeHandler( 27 | $this->get('validator'), 28 | $this->get('authbucket_oauth2.model_manager.factory') 29 | ); 30 | $handler->getAccessToken($request); 31 | } 32 | 33 | /** 34 | * @expectedException \AuthBucket\OAuth2\Exception\TemporarilyUnavailableException 35 | */ 36 | public function testExceptionCreateAccessToken() 37 | { 38 | $modelManagerFactory = new BarModelManagerFactory(); 39 | $handler = new MacTokenTypeHandler( 40 | $this->get('validator'), 41 | $this->get('authbucket_oauth2.model_manager.factory') 42 | ); 43 | $handler->createAccessToken($modelManagerFactory, 'foo'); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/TokenType/TokenTypeHandlerFactoryTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests\TokenType; 13 | 14 | use AuthBucket\Bundle\OAuth2Bundle\Tests\WebTestCase; 15 | use AuthBucket\OAuth2\TokenType\TokenTypeHandlerFactory; 16 | 17 | class TokenTypeHandlerFactoryTest extends WebTestCase 18 | { 19 | /** 20 | * @expectedException \AuthBucket\OAuth2\Exception\ServerErrorException 21 | */ 22 | public function testNonExistsTokenTypeHandler() 23 | { 24 | $classes = ['foo' => 'AuthBucket\\Bundle\OAuth2Bundle\\Tests\\TokenType\\NonExistsTokenTypeHandler']; 25 | $factory = new TokenTypeHandlerFactory( 26 | $this->get('validator'), 27 | $this->get('authbucket_oauth2.model_manager.factory'), 28 | $classes 29 | ); 30 | } 31 | 32 | /** 33 | * @expectedException \AuthBucket\OAuth2\Exception\ServerErrorException 34 | */ 35 | public function testBadAddTokenTypeHandler() 36 | { 37 | $classes = ['foo' => 'AuthBucket\\Bundle\\OAuth2Bundle\\Tests\\TokenType\\FooTokenTypeHandler']; 38 | $factory = new TokenTypeHandlerFactory( 39 | $this->get('validator'), 40 | $this->get('authbucket_oauth2.model_manager.factory'), 41 | $classes 42 | ); 43 | } 44 | 45 | /** 46 | * @expectedException \AuthBucket\OAuth2\Exception\ServerErrorException 47 | */ 48 | public function testBadGetTokenTypeHandler() 49 | { 50 | $classes = ['bar' => 'AuthBucket\\Bundle\\OAuth2Bundle\\Tests\\TokenType\\BarTokenTypeHandler']; 51 | $factory = new TokenTypeHandlerFactory( 52 | $this->get('validator'), 53 | $this->get('authbucket_oauth2.model_manager.factory'), 54 | $classes 55 | ); 56 | $handler = $factory->getTokenTypeHandler('foo'); 57 | } 58 | 59 | public function testGoodGetTokenTypeHandler() 60 | { 61 | $classes = ['bar' => 'AuthBucket\\Bundle\\OAuth2Bundle\\Tests\\TokenType\\BarTokenTypeHandler']; 62 | $factory = new TokenTypeHandlerFactory( 63 | $this->get('validator'), 64 | $this->get('authbucket_oauth2.model_manager.factory'), 65 | $classes 66 | ); 67 | $handler = $factory->getTokenTypeHandler('bar'); 68 | $this->assertSame($factory->getTokenTypeHandlers(), $classes); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /tests/WebTestCase.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace AuthBucket\Bundle\OAuth2Bundle\Tests; 13 | 14 | use Symfony\Bundle\FrameworkBundle\Client; 15 | use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; 16 | 17 | abstract class WebTestCase extends KernelTestCase 18 | { 19 | public function setUp() 20 | { 21 | static::bootKernel(); 22 | } 23 | 24 | public function createClient(array $server = []) 25 | { 26 | $client = static::$kernel->getContainer()->get('test.client'); 27 | $client->setServerParameters($server); 28 | 29 | return $client; 30 | } 31 | 32 | public function set($id, $service) 33 | { 34 | return static::$kernel->getContainer()->set($id, $service); 35 | } 36 | 37 | public function get($id) 38 | { 39 | return static::$kernel->getContainer()->get($id); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /var/bootstrap.php: -------------------------------------------------------------------------------- 1 | 17 | Options -MultiViews 18 | 19 | 20 | 21 | RewriteEngine On 22 | 23 | # Determine the RewriteBase automatically and set it as environment variable. 24 | # If you are using Apache aliases to do mass virtual hosting or installed the 25 | # project in a subdirectory, the base path will be prepended to allow proper 26 | # resolution of the app.php file and to redirect to the correct URI. It will 27 | # work in environments without path prefix as well, providing a safe, one-size 28 | # fits all solution. But as you do not need it in this case, you can comment 29 | # the following 2 lines to eliminate the overhead. 30 | RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ 31 | RewriteRule ^(.*) - [E=BASE:%1] 32 | 33 | # Sets the HTTP_AUTHORIZATION header removed by apache 34 | RewriteCond %{HTTP:Authorization} . 35 | RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 36 | 37 | # Redirect to URI without front controller to prevent duplicate content 38 | # (with and without `/app.php`). Only do this redirect on the initial 39 | # rewrite by Apache and not on subsequent cycles. Otherwise we would get an 40 | # endless redirect loop (request -> rewrite to front controller -> 41 | # redirect -> request -> ...). 42 | # So in case you get a "too many redirects" error or you always get redirected 43 | # to the start page because your Apache does not expose the REDIRECT_STATUS 44 | # environment variable, you have 2 choices: 45 | # - disable this feature by commenting the following 2 lines or 46 | # - use Apache >= 2.3.9 and replace all L flags by END flags and remove the 47 | # following RewriteCond (best solution) 48 | RewriteCond %{ENV:REDIRECT_STATUS} ^$ 49 | RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L] 50 | 51 | # If the requested filename exists, simply serve it. 52 | # We only want to let Apache serve files and not directories. 53 | RewriteCond %{REQUEST_FILENAME} -f 54 | RewriteRule .? - [L] 55 | 56 | # Rewrite all other queries to the front controller. 57 | RewriteRule .? %{ENV:BASE}/app.php [L] 58 | 59 | 60 | 61 | 62 | # When mod_rewrite is not available, we instruct a temporary redirect of 63 | # the start page to the front controller explicitly so that the website 64 | # and the generated links can still be used. 65 | RedirectMatch 302 ^/$ /app.php/ 66 | # RedirectTemp cannot be used instead 67 | 68 | 69 | -------------------------------------------------------------------------------- /web/app.php: -------------------------------------------------------------------------------- 1 | loadClassCache(); 11 | 12 | // When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter 13 | //Request::enableHttpMethodParameterOverride(); 14 | $request = Request::createFromGlobals(); 15 | $response = $kernel->handle($request); 16 | $response->send(); 17 | $kernel->terminate($request, $response); 18 | -------------------------------------------------------------------------------- /web/app_dev.php: -------------------------------------------------------------------------------- 1 | loadClassCache(); 27 | $request = Request::createFromGlobals(); 28 | $response = $kernel->handle($request); 29 | $response->send(); 30 | $kernel->terminate($request, $response); 31 | -------------------------------------------------------------------------------- /web/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/authbucket/oauth2-symfony-bundle/ae9faa3c9237dcac711dedf471aae4a83b1168f2/web/apple-touch-icon.png -------------------------------------------------------------------------------- /web/css/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-bottom: 20px; 3 | padding-top: 20px; 4 | } 5 | pre code { 6 | overflow: auto; 7 | white-space: pre; 8 | } 9 | footer.authbucket-docs-footer { 10 | border-top: 1px solid #eee; 11 | margin-top: 100px; 12 | padding-bottom: 40px; 13 | padding-top: 40px; 14 | text-align: center; 15 | } 16 | -------------------------------------------------------------------------------- /web/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/authbucket/oauth2-symfony-bundle/ae9faa3c9237dcac711dedf471aae4a83b1168f2/web/favicon.ico -------------------------------------------------------------------------------- /web/robots.txt: -------------------------------------------------------------------------------- 1 | # www.robotstxt.org/ 2 | # www.google.com/support/webmasters/bin/answer.py?hl=en&answer=156449 3 | 4 | User-agent: * 5 | --------------------------------------------------------------------------------