Skip to content

Commit

Permalink
Merge pull request #167 from Sicaa/linkedin-fields-option
Browse files Browse the repository at this point in the history
Adding "api_version" and "fields" options for Linkedin's provider
  • Loading branch information
weaverryan authored Mar 25, 2019
2 parents aa5e8e5 + e09ab30 commit f0f1056
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class FacebookController extends Controller
public function connectAction(ClientRegistry $clientRegistry)
{
// on Symfony 3.3 or lower, $clientRegistry = $this->get('knpu.oauth2.registry');
// will redirect to Facebook!
return $clientRegistry
->getClient('facebook_main') // key used in config/packages/knpu_oauth2_client.yaml
Expand Down Expand Up @@ -950,7 +950,10 @@ knpu_oauth2_client:
# a route name you'll create
redirect_route: connect_linkedin_check
redirect_params: {}

# Optional value to specify Linkedin's API version to use. As the time of writing, v1 is still used by default by league/oauth2-linkedin.
# api_version: null
# Optional value to specify fields to be requested from the profile. Since Linkedin\'s API upgrade from v1 to v2, fields and authorizations policy have been enforced. See https://docs.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/sign-in-with-linkedin for more details.
# fields: []
# whether to check OAuth2 "state": defaults to true
# use_state: true

Expand Down Expand Up @@ -1286,7 +1289,7 @@ you can use.

## Extending/Decorating Client Classes

Maybe you need some extra services inside your client class? No problem! You can
Maybe you need some extra services inside your client class? No problem! You can
decorate existing client class with your own implementation. All you need is
new class that implement OAuth2ClientInterface:

Expand Down
23 changes: 21 additions & 2 deletions src/DependencyInjection/Providers/LinkedInProviderConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@ class LinkedInProviderConfigurator implements ProviderConfiguratorInterface
{
public function buildConfiguration(NodeBuilder $node)
{
// no custom options
$node
->integerNode('api_version')
->defaultNull()
->info('Optional value to specify Linkedin\'s API version to use. As the time of writing, v1 is still used by default by league/oauth2-linkedin.')
->end()
->arrayNode('fields')
->prototype('scalar')->end()
->info('Optional value to specify fields to be requested from the profile. Since Linkedin\'s API upgrade from v1 to v2, fields and authorizations policy have been enforced. See https://docs.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/sign-in-with-linkedin for more details.')
->end()
;
}

public function getProviderClass(array $config)
Expand All @@ -26,10 +35,20 @@ public function getProviderClass(array $config)

public function getProviderOptions(array $config)
{
return [
$options = [
'clientId' => $config['client_id'],
'clientSecret' => $config['client_secret'],
];

if (!is_null($config['api_version'])) {
$options['resourceOwnerVersion'] = $config['api_version'];
}

if (!empty($config['fields'])) {
$options['fields'] = $config['fields'];
}

return $options;
}

public function getPackagistName()
Expand Down

0 comments on commit f0f1056

Please sign in to comment.