From 02cc9f48ad32758296b0d2139bc87cfd3a5c297c Mon Sep 17 00:00:00 2001 From: Florent Monbillard Date: Wed, 24 Sep 2014 18:45:53 -0500 Subject: [PATCH] Support for picture-urls::(original) and profile picture - fetch picture-urls::(original) field instead of picture-url - use the first image of pictureUrls array as profile image - update README to reflect these changes --- README.md | 2 +- lib/omniauth/strategies/linkedin.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b9789a5..16ebe7f 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ provider :linkedin, ENV['LINKEDIN_KEY'], ENV['LINKEDIN_SECRET'], :scope => 'r_fu When specifying which permissions you want to users to grant to your application, you will probably want to specify the array of fields that you want returned in the omniauth hash. The list of default fields is as follows: ```ruby -['id', 'email-address', 'first-name', 'last-name', 'headline', 'location', 'industry', 'picture-url', 'public-profile-url'] +['id', 'email-address', 'first-name', 'last-name', 'headline', 'location', 'industry', 'picture-urls::(original)', 'public-profile-url'] ``` Here's an example of a possible configuration where the fields returned from the API are: id, email-address, first-name and last-name. diff --git a/lib/omniauth/strategies/linkedin.rb b/lib/omniauth/strategies/linkedin.rb index bb28cea..e536c23 100755 --- a/lib/omniauth/strategies/linkedin.rb +++ b/lib/omniauth/strategies/linkedin.rb @@ -15,7 +15,7 @@ class LinkedIn < OmniAuth::Strategies::OAuth2 } option :scope, 'r_basicprofile r_emailaddress' - option :fields, ['id', 'email-address', 'first-name', 'last-name', 'headline', 'location', 'industry', 'picture-url', 'public-profile-url'] + option :fields, ['id', 'email-address', 'first-name', 'last-name', 'headline', 'location', 'industry', 'picture-urls::(original)', 'public-profile-url'] # These are called after authentication has succeeded. If # possible, you should try to set the UID without making @@ -33,7 +33,7 @@ class LinkedIn < OmniAuth::Strategies::OAuth2 :last_name => raw_info['lastName'], :location => raw_info['location'], :description => raw_info['headline'], - :image => raw_info['pictureUrl'], + :image => raw_info.fetch('pictureUrls', {}).fetch('values', []).first, :urls => { 'public_profile' => raw_info['publicProfileUrl'] }