Class: OmniAuth::Strategies::LinkedIn

Inherits:
OAuth
  • Object
show all
Defined in:
lib/omniauth/strategies/oauth/linked_in.rb

Instance Attribute Summary

Attributes inherited from OAuth

#consumer_key, #consumer_options, #consumer_secret, #name

Instance Method Summary collapse

Methods inherited from OAuth

#callback_phase, #consumer, #request_phase, #unique_id

Constructor Details

#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ LinkedIn

Returns a new instance of LinkedIn.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/omniauth/strategies/oauth/linked_in.rb', line 7

def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
  client_options = {
    :access_token_path => '/uas/oauth/accessToken',
    :authorize_path => '/uas/oauth/authorize',
    :request_token_path => '/uas/oauth/requestToken',
    :scheme => :header,
    :site => 'https://api.linkedin.com',
  }
  client_options[:authorize_path] = '/uas/oauth/authenticate' unless options[:sign_in] == false
  super(app, :linked_in, consumer_key, consumer_secret, client_options, options, &block)
end

Instance Method Details

#auth_hashObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/omniauth/strategies/oauth/linked_in.rb', line 19

def auth_hash
  hash = user_hash(@access_token)

  OmniAuth::Utils.deep_merge(super,
    {
      'uid' => hash.delete('id'),
      'user_info' => hash,
    }
  )
end

#user_hash(access_token) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/omniauth/strategies/oauth/linked_in.rb', line 30

def user_hash(access_token)
 person = MultiXml.parse(@access_token.get('/v1/people/~:(id,first-name,last-name,headline,member-url-resources,picture-url,location,public-profile-url)').body)['person']

  hash = {
    'id' => person['id'],
    'first_name' => person['first_name'],
    'last_name' => person['last_name'],
    'nickname' => person['public_profile_url'].to_s.split('/').last,
    'location' => person['location']['name'],
    'image' => person['picture_url'],
    'description' => person['headline'],
    'public_profile_url' => person['public_profile_url'],
  }
  hash['urls'] = {}
  member_urls = person['member_url_resources']['member_url']
  if (!member_urls.nil?) and (!member_urls.empty?)
    [member_urls].flatten.each do |url|
      hash['urls']["#{url['name']}"] = url['url']
    end
  end
  hash['urls']['LinkedIn'] = person['public_profile_url']
  hash['name'] = "#{hash['first_name']} #{hash['last_name']}"
  hash
end