Skip to content

Commit d499b85

Browse files
committed
Merge PR #383 into master
2 parents fbf3107 + 7a19147 commit d499b85

File tree

6 files changed

+192
-56
lines changed

6 files changed

+192
-56
lines changed

Controller/AuthorizeController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ protected function getClient()
152152
if (null !== $request) {
153153
if (null === $clientId = $request->get('client_id')) {
154154
$form = $this->container->get('fos_oauth_server.authorize.form');
155-
$clientId = $request->get(sprintf('%s[client_id]', $form->getName()), null, true);
155+
$formData = $request->get($form->getName(), array());
156+
$clientId = isset($formData['client_id']) ? $formData['client_id'] : null;
156157
}
157158

158159
$client = $this->container

DependencyInjection/FOSOAuthServerExtension.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\DependencyInjection\ContainerBuilder;
1919
use Symfony\Component\DependencyInjection\Alias;
2020
use Symfony\Component\Config\FileLocator;
21+
use FOS\OAuthServerBundle\Util\LegacyFormHelper;
2122

2223
class FOSOAuthServerExtension extends Extension
2324
{
@@ -147,7 +148,14 @@ protected function loadAuthorize(array $config, ContainerBuilder $container, Xml
147148

148149
$container->setAlias('fos_oauth_server.authorize.form.handler', $config['form']['handler']);
149150
unset($config['form']['handler']);
150-
151+
152+
if (!LegacyFormHelper::isLegacy() && $config['form']['type'] === 'fos_oauth_server_authorize') {
153+
154+
$authorizeFormTypeDefinition = $container->getDefinition('fos_oauth_server.authorize.form.type');
155+
$config['form']['type'] = $authorizeFormTypeDefinition->getClass();
156+
157+
}
158+
151159
$this->remapParametersNamespaces($config, $container, array(
152160
'form' => 'fos_oauth_server.authorize.form.%s',
153161
));

Form/Type/AuthorizeFormType.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Form\AbstractType;
1616
use Symfony\Component\OptionsResolver\OptionsResolver;
1717
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
18+
use FOS\OAuthServerBundle\Util\LegacyFormHelper;
1819

1920
/**
2021
* @author Chris Jones <[email protected]>
@@ -23,11 +24,13 @@ class AuthorizeFormType extends AbstractType
2324
{
2425
public function buildForm(FormBuilderInterface $builder, array $options)
2526
{
26-
$builder->add('client_id', 'hidden');
27-
$builder->add('response_type', 'hidden');
28-
$builder->add('redirect_uri', 'hidden');
29-
$builder->add('state', 'hidden');
30-
$builder->add('scope', 'hidden');
27+
$hiddenType = LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\HiddenType');
28+
29+
$builder->add('client_id', $hiddenType);
30+
$builder->add('response_type', $hiddenType);
31+
$builder->add('redirect_uri', $hiddenType);
32+
$builder->add('state', $hiddenType);
33+
$builder->add('scope', $hiddenType);
3134
}
3235

3336
/**
@@ -53,8 +56,16 @@ public function configureOptions(OptionsResolver $resolver)
5356
/**
5457
* @return string
5558
*/
56-
public function getName()
59+
public function getBlockPrefix()
5760
{
5861
return 'fos_oauth_server_authorize';
5962
}
63+
64+
/**
65+
* @return string
66+
*/
67+
public function getName()
68+
{
69+
return $this->getBlockPrefix();
70+
}
6071
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace FOS\OAuthServerBundle\Tests\Form\Type;
4+
5+
use FOS\OAuthServerBundle\Form\Type\AuthorizeFormType;
6+
use FOS\OAuthServerBundle\Form\Model\Authorize;
7+
use FOS\OAuthServerBundle\Util\LegacyFormHelper;
8+
use Symfony\Component\Form\Test\TypeTestCase;
9+
use Symfony\Component\Form\FormBuilder;
10+
use Symfony\Component\Form\Forms;
11+
12+
class AuthorizeFormTypeTest extends TypeTestCase
13+
{
14+
protected function setUp()
15+
{
16+
parent::setUp();
17+
18+
$this->factory = Forms::createFormFactoryBuilder()
19+
->addTypes($this->getTypes())
20+
->getFormFactory();
21+
22+
$this->builder = new FormBuilder(null, null, $this->dispatcher, $this->factory);
23+
}
24+
25+
public function testSubmit()
26+
{
27+
$accepted = 'true';
28+
$formData = array(
29+
'client_id' => '1',
30+
'response_type' => 'code',
31+
'redirect_uri'=>'http:\\localhost\test.php',
32+
'state'=>'testState',
33+
'scope'=>'testScope',
34+
);
35+
36+
$authorize = new Authorize($accepted, $formData);
37+
38+
$form = $this->factory->create(LegacyFormHelper::getType('FOS\OAuthServerBundle\Form\Type\AuthorizeFormType'), $authorize);
39+
40+
$form->submit($formData);
41+
42+
$this->assertTrue($form->isSynchronized());
43+
$this->assertEquals($authorize, $form->getData());
44+
$this->assertEquals((bool) $accepted, $authorize->accepted);
45+
46+
$view = $form->createView();
47+
$children = $view->children;
48+
49+
foreach (array_keys($formData) as $key) {
50+
$this->assertArrayHasKey($key, $children);
51+
}
52+
}
53+
54+
protected function getTypes()
55+
{
56+
return array(
57+
new AuthorizeFormType(),
58+
);
59+
}
60+
}

Util/LegacyFormHelper.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSOAuthServerBundle package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
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 FOS\OAuthServerBundle\Util;
13+
14+
/**
15+
* @internal
16+
*
17+
* @author Sanjay Pillai <[email protected]>
18+
*/
19+
final class LegacyFormHelper
20+
{
21+
private static $map = array(
22+
'Symfony\Component\Form\Extension\Core\Type\HiddenType' => 'hidden',
23+
'FOS\OAuthServerBundle\Form\Type\AuthorizeFormType'=> 'fos_oauth_server_authorize'
24+
);
25+
26+
public static function getType($class)
27+
{
28+
if (!self::isLegacy()) {
29+
return $class;
30+
}
31+
32+
if (!isset(self::$map[$class])) {
33+
throw new \InvalidArgumentException(sprintf('Form type with class "%s" can not be found. Please check for typos or add it to the map in LegacyFormHelper', $class));
34+
}
35+
36+
return self::$map[$class];
37+
}
38+
39+
public static function isLegacy()
40+
{
41+
return !method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix');
42+
}
43+
44+
private function __construct()
45+
{
46+
}
47+
48+
private function __clone()
49+
{
50+
}
51+
}

composer.json

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,54 @@
11
{
2-
"name": "friendsofsymfony/oauth-server-bundle",
3-
"type": "symfony-bundle",
4-
"description": "Symfony2 OAuth Server Bundle",
5-
"keywords": ["oauth", "oauth2", "server"],
6-
"homepage": "http://friendsofsymfony.github.com",
7-
"license": "MIT",
8-
"authors": [
9-
{
10-
"name": "Arnaud Le Blanc",
11-
"email": "[email protected]"
12-
},
13-
{
14-
"name": "FriendsOfSymfony Community",
15-
"homepage": "https://github.com/FriendsOfSymfony/FOSOAuthServerBundle/contributors"
16-
}
17-
],
18-
"require": {
19-
"php": ">=5.3.3",
20-
"friendsofsymfony/oauth2-php": "~1.1",
21-
"symfony/framework-bundle": "~2.2|~3.0",
22-
"symfony/security-bundle": "~2.1|~3.0"
23-
},
24-
"require-dev": {
25-
"symfony/class-loader": "~2.1|~3.0",
26-
"symfony/yaml": "~2.1|~3.0",
27-
"willdurand/propel-typehintable-behavior": "^1.0.4",
28-
"propel/propel1": "^1.6.5",
29-
"phing/phing": "~2.4",
30-
"doctrine/mongodb-odm": "~1.0",
31-
"doctrine/doctrine-bundle": "~1.0",
32-
"doctrine/orm": "~2.2"
33-
},
34-
"suggest": {
35-
"doctrine/doctrine-bundle": "*",
36-
"doctrine/mongodb-odm-bundle": "*",
37-
"propel/propel-bundle": "If you want to use Propel with Symfony2, then you will have to install the PropelBundle",
38-
"willdurand/propel-typehintable-behavior": "The Typehintable behavior is useful to add type hints on generated methods, to be compliant with interfaces"
39-
},
40-
"autoload": {
41-
"psr-4": { "FOS\\OAuthServerBundle\\": "" }
42-
},
43-
"extra": {
44-
"branch-alias": {
45-
"dev-master": "1.5-dev"
46-
}
47-
}
48-
49-
}
2+
"name" : "friendsofsymfony/oauth-server-bundle",
3+
"type" : "symfony-bundle",
4+
"description" : "Symfony2 OAuth Server Bundle",
5+
"keywords" : [
6+
"oauth",
7+
"oauth2",
8+
"server"
9+
],
10+
"homepage" : "http://friendsofsymfony.github.com",
11+
"license" : "MIT",
12+
"authors" : [{
13+
"name" : "Arnaud Le Blanc",
14+
"email" : "[email protected]"
15+
}, {
16+
"name" : "FriendsOfSymfony Community",
17+
"homepage" : "https://github.com/FriendsOfSymfony/FOSOAuthServerBundle/contributors"
18+
}
19+
],
20+
"require" : {
21+
"php" : ">=5.3.3",
22+
"friendsofsymfony/oauth2-php" : "~1.1",
23+
"symfony/framework-bundle" : "~2.2|~3.0",
24+
"symfony/security-bundle" : "~2.1|~3.0"
25+
},
26+
"require-dev" : {
27+
"symfony/class-loader" : "~2.1|~3.0",
28+
"symfony/yaml" : "~2.1|~3.0",
29+
"willdurand/propel-typehintable-behavior" : "^1.0.4",
30+
"propel/propel1" : "^1.6.5",
31+
"phing/phing" : "~2.4",
32+
"doctrine/mongodb-odm" : "~1.0",
33+
"doctrine/doctrine-bundle" : "~1.0",
34+
"doctrine/orm" : "~2.2",
35+
"symfony/form" : "~2.3|~3.0"
36+
},
37+
"suggest" : {
38+
"doctrine/doctrine-bundle" : "*",
39+
"doctrine/mongodb-odm-bundle" : "*",
40+
"propel/propel-bundle" : "If you want to use Propel with Symfony2, then you will have to install the PropelBundle",
41+
"willdurand/propel-typehintable-behavior" : "The Typehintable behavior is useful to add type hints on generated methods, to be compliant with interfaces",
42+
"symfony/form" : "If you want to use the Authorize form, then you will have to install the Symfony Form Component"
43+
},
44+
"autoload" : {
45+
"psr-4" : {
46+
"FOS\\OAuthServerBundle\\" : ""
47+
}
48+
},
49+
"extra" : {
50+
"branch-alias" : {
51+
"dev-master" : "1.5-dev"
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)