Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding "api_version" and "fields" options for Linkedin's provider #167

Merged
merged 2 commits into from
Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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