Reputation: 10561
I followed this gist https://gist.github.com/danvbe/4476697 to get HWIOauthBundle to work on my site, and now I can login fine via a LinkedIn account and persist the user to my local database, so I'm pretty happy with that. However, my next step is to retrieve more information about the user via the LinkedIn API, and for now I only have the username and the formatted-name fields.
I've looked around in the code, the interesting chunk of code is in OAuth/ResourceOwner/LinkedinResourceOwner.php:
protected $options = array(
'authorization_url' => 'https://www.linkedin.com/uas/oauth/authenticate',
'request_token_url' => 'https://api.linkedin.com/uas/oauth/requestToken',
'access_token_url' => 'https://api.linkedin.com/uas/oauth/accessToken',
'infos_url' => 'http://api.linkedin.com/v1/people/~:(id,formatted-name)',
'realm' => 'http://api.linkedin.com',
);
So i thought I only needed to overwrite this ResourceOwner and modify the line
'infos_url' => 'http://api.linkedin.com/v1/people/~:(id,formatted-name)',
by adding other fields. My idea was to create a MylinkedinResourceOwner class which extends the original LinkedinResourceOwner class. So that was what i did, and I added in my services.yml the following lines:
hwi_oauth.resource_owner.mylinkedin.class: Acme\UserBundle\OAuth\ResourceOwner\MylinkedinResourceOwner
hwi_oauth.abstract_resource_owner.mylinkedin:
class: "%hwi_oauth.resource_owner.mylinkedin.class%"
parent: hwi_oauth.abstract_resource_owner.oauth2
and of course changed in config.yml:
hwi_oauth:
resource_owners:
linkedin:
type: mylinkedin
client_id: ***
client_secret: ***
scope: r_fullprofile
But unfortunately I have the following error
InvalidConfigurationException: Invalid configuration for path "hwi_oauth.resource_owners.linkedin.type": Unknown resource owner type "mylinkedin".
So my question is: am I doing this right to get additional information of a LinkedIn account ? If so, how can I solve this error ?
Thanks !
Upvotes: 1
Views: 2788
Reputation: 2188
Just a note to whoever stumbles on this:
It must be https, and make sure it's json if that's what you're expecting:
infos_url: "https://api.linkedin.com/v1/people/~:(id,first-name,last-name,formatted-name,email-address)?format=json"
Upvotes: 1
Reputation: 432
To get the linkedin email and profile-picture url for HWIOauthBundle I used this configuration.
....
resource_owners:
linkedin:
type: linkedin
client_id: ***
client_secret: ***
infos_url: http://api.linkedin.com/v1/people/~:(id,formatted-name,email-address,picture-url)
scope: "r_basicprofile,r_emailaddress"
paths:
email: emailAddress
profilepicture: pictureUrl
Upvotes: 0
Reputation: 10561
I finally found it, actually it's much simpler than what I did. The only thing I needed to do was to add a infos_url property in config.yml like this:
hwi_oauth:
resource_owners:
linkedin:
type: mylinkedin
client_id: ***
client_secret: ***
scope: r_fullprofile
infos_url: http://api.linkedin.com/v1/people/~:(id,first-name,last-name)
So no custom ResourceOwner at all.
Upvotes: 0