|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sludio\HelperBundle\Oauth\Configurator; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeBuilder; |
|
6
|
|
|
use Sludio\HelperBundle\Oauth\Client\Provider\Facebook\Facebook; |
|
7
|
|
|
use Sludio\HelperBundle\Oauth\Client\Client\FacebookOAuthClient; |
|
8
|
|
|
|
|
9
|
|
|
class FacebookProviderConfigurator implements ProviderConfiguratorInterface |
|
10
|
|
|
{ |
|
11
|
|
|
public function buildConfiguration(NodeBuilder $node) |
|
12
|
|
|
{ |
|
13
|
|
|
// @formatter:off |
|
14
|
|
|
$node |
|
15
|
|
|
->scalarNode('graph_api_version') |
|
16
|
|
|
->isRequired() |
|
17
|
|
|
->defaultValue('v2.8') |
|
18
|
|
|
->end() |
|
19
|
|
|
->arrayNode('fields') |
|
|
|
|
|
|
20
|
|
|
->beforeNormalization() |
|
21
|
|
|
->ifString() |
|
22
|
|
|
->then(function($v) { |
|
23
|
|
|
return preg_split('/\s*,\s*/', $v); |
|
24
|
|
|
}) |
|
25
|
|
|
->end() |
|
26
|
|
|
->prototype('scalar')->end() |
|
27
|
|
|
->validate() |
|
28
|
|
|
->ifTrue(function($value) { |
|
29
|
|
|
$fields = \explode(';', Facebook::FIELDS); |
|
30
|
|
|
foreach ($value as $v) { |
|
31
|
|
|
foreach (preg_split('/\s*,\s*/', $v) as $item) { |
|
32
|
|
|
if (!\in_array($item, $fields)) { |
|
33
|
|
|
return true; |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
}) |
|
38
|
|
|
->thenInvalid('Unsupported field. Supported fields: '.Facebook::FIELDS) |
|
39
|
|
|
->end() |
|
40
|
|
|
->defaultValue([]) |
|
41
|
|
|
->end() |
|
42
|
|
|
->scalarNode('client_class') |
|
43
|
|
|
->info('If you have a sub-class of OAuth2Client you want to use, add it here') |
|
44
|
|
|
->defaultValue(FacebookOAuthClient::class) |
|
45
|
|
|
->end() |
|
46
|
|
|
->scalarNode('redirect_route') |
|
47
|
|
|
->isRequired() |
|
48
|
|
|
->cannotBeEmpty() |
|
49
|
|
|
->end() |
|
50
|
|
|
->arrayNode('provider_options') |
|
51
|
|
|
->info('Other options to pass to your provider\'s constructor') |
|
52
|
|
|
->prototype('variable')->end() |
|
53
|
|
|
->end() |
|
54
|
|
|
; |
|
55
|
|
|
// @formatter:on |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function getProviderClass(array $config) |
|
59
|
|
|
{ |
|
60
|
|
|
return Facebook::class; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function getProviderOptions(array $config) |
|
64
|
|
|
{ |
|
65
|
|
|
return array_merge([ |
|
66
|
|
|
'clientId' => $config['client_id'], |
|
67
|
|
|
'clientSecret' => $config['client_secret'], |
|
68
|
|
|
'graphApiVersion' => $config['graph_api_version'], |
|
69
|
|
|
'redirect_route' => $config['redirect_route'], |
|
70
|
|
|
'fields' => $config['fields'], |
|
71
|
|
|
], $config['provider_options']); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function getProviderDisplayName() |
|
75
|
|
|
{ |
|
76
|
|
|
return 'Facebook'; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function getClientClass(array $config) |
|
80
|
|
|
{ |
|
81
|
|
|
return $config['client_class']; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|