diff --git a/lib/omniauth/strategies/linkedin.rb b/lib/omniauth/strategies/linkedin.rb index ecff8a5..aecc5b5 100755 --- a/lib/omniauth/strategies/linkedin.rb +++ b/lib/omniauth/strategies/linkedin.rb @@ -19,12 +19,7 @@ class LinkedIn < OmniAuth::Strategies::OAuth2 end info do - { - :email => email_address, - :first_name => localized_field('firstName'), - :last_name => localized_field('lastName'), - :picture_url => picture_url - } + options.scope.include?('r_basicprofile') ? lite_info.merge(basic_info) : lite_info end extra do @@ -52,6 +47,23 @@ def raw_info private + def lite_info + { + :email => email_address, + :first_name => localized_field('firstName'), + :last_name => localized_field('lastName'), + :picture_url => picture_url + } + end + + def basic_info + { + :vanity_name => raw_info['vanityName'], + :maiden_name => localized_field('maidenName'), + :headline => localized_field('headline') + } + end + def email_address if options.fields.include? 'email-address' fetch_email_address @@ -81,7 +93,10 @@ def fields_mapping 'id' => 'id', 'first-name' => 'firstName', 'last-name' => 'lastName', - 'picture-url' => 'profilePicture(displayImage~:playableStreams)' + 'picture-url' => 'profilePicture(displayImage~:playableStreams)', + 'vanity-name' => 'vanityName', + 'maiden-name' => 'maidenName', + 'headline' => 'headline' } end diff --git a/spec/omniauth/strategies/linkedin_spec.rb b/spec/omniauth/strategies/linkedin_spec.rb index 02765af..206ce9d 100755 --- a/spec/omniauth/strategies/linkedin_spec.rb +++ b/spec/omniauth/strategies/linkedin_spec.rb @@ -39,6 +39,7 @@ end describe '#info / #raw_info' do + let(:access_token) { instance_double OAuth2::AccessToken } let(:parsed_response) { Hash[:foo => 'bar'] } @@ -61,13 +62,51 @@ .and_return(profile_response) end - it 'returns parsed responses using access token' do - expect(subject.info).to have_key :email - expect(subject.info).to have_key :first_name - expect(subject.info).to have_key :last_name - expect(subject.info).to have_key :picture_url + context 'lite_profile' do + it 'returns parsed responses using access token' do + expect(subject.options.scope).to eq('r_liteprofile r_emailaddress') + expect(subject.info).to have_key :email + expect(subject.info).to have_key :first_name + expect(subject.info).to have_key :last_name + expect(subject.info).to have_key :picture_url - expect(subject.raw_info).to eq({ :foo => 'bar' }) + expect(subject.raw_info).to eq({ :foo => 'bar' }) + end + end + + context 'basic_profile' do + subject do + OmniAuth::Strategies::LinkedIn.new( + nil, + scope: 'r_basicprofile r_emailaddress', + fields: [ + 'id', + 'first-name', + 'last-name', + 'headline', + 'picture-url', + 'profile-url', + 'email-address', + 'vanity-name', + 'maiden-name' + ] + ) + end + + let(:profile_endpoint) { '/v2/me?projection=(id,firstName,lastName,headline,profilePicture(displayImage~:playableStreams),vanityName,maidenName)' } + + it 'returns parsed responses using access token' do + expect(subject.options.scope).to eq('r_basicprofile r_emailaddress') + expect(subject.info).to have_key :email + expect(subject.info).to have_key :first_name + expect(subject.info).to have_key :last_name + expect(subject.info).to have_key :picture_url + expect(subject.info).to have_key :vanity_name + expect(subject.info).to have_key :maiden_name + expect(subject.info).to have_key :headline + + expect(subject.raw_info).to eq(:foo => 'bar') + end end end