ozo2003 /
HelperBundle
| 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\Google\Google; |
||
| 7 | use Sludio\HelperBundle\Oauth\Client\Client\GoogleOAuth2Client; |
||
| 8 | |||
| 9 | class GoogleProviderConfigurator implements ProviderConfiguratorInterface |
||
| 10 | { |
||
| 11 | public function buildConfiguration(NodeBuilder $node) |
||
| 12 | { |
||
| 13 | // @formatter:off |
||
| 14 | $node |
||
| 15 | ->scalarNode('access_type') |
||
| 16 | ->defaultValue(null) |
||
| 17 | ->info('Optional value for sending access_type parameter. More detail: https://developers.google.com/identity/protocols/OpenIDConnect#authenticationuriparameters') |
||
| 18 | ->end() |
||
| 19 | ->scalarNode('hosted_domain') |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 20 | ->defaultValue(null) |
||
| 21 | ->info('Optional value for sending hd parameter. More detail: https://developers.google.com/identity/protocols/OpenIDConnect#hd-param') |
||
| 22 | ->end() |
||
| 23 | ->arrayNode('user_fields') |
||
| 24 | ->prototype('scalar')->end() |
||
| 25 | ->info('Optional value for additional fields to be requested from the user profile. If set, these values will be included with the defaults. More details: https://developers.google.com/+/web/api/rest/latest/people') |
||
| 26 | ->end() |
||
| 27 | ->scalarNode('client_class') |
||
| 28 | ->info('If you have a sub-class of OAuth2Client you want to use, add it here') |
||
| 29 | ->defaultValue(GoogleOAuth2Client::class) |
||
| 30 | ->end() |
||
| 31 | ->scalarNode('redirect_route') |
||
| 32 | ->isRequired() |
||
| 33 | ->cannotBeEmpty() |
||
| 34 | ->end() |
||
| 35 | ->arrayNode('provider_options') |
||
| 36 | ->info('Other options to pass to your provider\'s constructor') |
||
| 37 | ->prototype('variable')->end() |
||
| 38 | ->end() |
||
| 39 | ; |
||
| 40 | // @formatter:on |
||
| 41 | } |
||
| 42 | |||
| 43 | public function getProviderClass(array $config) |
||
| 44 | { |
||
| 45 | return Google::class; |
||
| 46 | } |
||
| 47 | |||
| 48 | public function getProviderOptions(array $config) |
||
| 49 | { |
||
| 50 | $options = [ |
||
| 51 | 'clientId' => $config['client_id'], |
||
| 52 | 'clientSecret' => $config['client_secret'], |
||
| 53 | 'redirect_route' => $config['redirect_route'], |
||
| 54 | ]; |
||
| 55 | |||
| 56 | if ($config['access_type']) { |
||
| 57 | $options['accessType'] = $config['access_type']; |
||
| 58 | } |
||
| 59 | |||
| 60 | if ($config['hosted_domain']) { |
||
| 61 | $options['hostedDomain'] = $config['hosted_domain']; |
||
| 62 | } |
||
| 63 | |||
| 64 | if (!empty($config['user_fields'])) { |
||
| 65 | $options['userFields'] = $config['user_fields']; |
||
| 66 | } |
||
| 67 | |||
| 68 | return array_merge($options, $config['provider_options']); |
||
| 69 | } |
||
| 70 | |||
| 71 | public function getProviderDisplayName() |
||
| 72 | { |
||
| 73 | return 'Google'; |
||
| 74 | } |
||
| 75 | |||
| 76 | public function getClientClass(array $config) |
||
| 77 | { |
||
| 78 | return $config['client_class']; |
||
| 79 | } |
||
| 80 | } |
||
| 81 |