Skip to content
Open
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
29 changes: 22 additions & 7 deletions lib/omniauth/strategies/linkedin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
51 changes: 45 additions & 6 deletions spec/omniauth/strategies/linkedin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
end

describe '#info / #raw_info' do

let(:access_token) { instance_double OAuth2::AccessToken }

let(:parsed_response) { Hash[:foo => 'bar'] }
Expand All @@ -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

Expand Down