AragornStack
AragornStack

Reputation: 63

How to display linkedin profile information in Rails

I'm working on an app that will have a linkedin sign in button. Once the user signs in using their linkedin in username and password. I want to display their information on the home page.

Currently I'm using 'omniauth', 'omniauth-linkedin-oauth2' to authenticate the user. The person working on this before me completed the authentication process but I can't understand how to display the users info. The authentication was implemented by following RailsCast #235 & #236 Omniauth Part 1 and 2.

This is the omniauth.rb file.

Rails.application.config.middleware.use OmniAuth::Builder do
provider :linkedin, 'LINKEDIN_KEY', 'LINKEDIN_SECRET', :scope => 'r_fullprofile r_emailaddress r_network', :fields => ['id', 'email-address', 'first-name', 'last-name']
end

I want to display all the fields from the omniauth.rb file. I understand its a really silly issue but I'm really new to Ruby on Rails so I'd greatly appreciate it if someone can guide me through the process.

Upvotes: 0

Views: 366

Answers (1)

mohameddiaa27
mohameddiaa27

Reputation: 3597

Based on the Authentications Controller in Part 2 You can get the fields from the omniauth hash:

omniauth = request.env["omniauth.auth"]
first_name = omniauth[:info][:first_name]
last_name = omniauth[:info][:last_name]
summary = omniauth[:extra][:raw_info][:summary]
headline = omniauth[:extra][:raw_info][:headline]
image = omniauth[:info][:image]
email = omniauth[:info][:email]
token = omniauth[:credentials][:token]
secret = omniauth[:credentials][:secret]
profile_url = omniauth[:info][:urls][:public_profile]

Those are the basic info you need from the authentication hash, if you need more data, you can use the following gem (using the user's token):

gem 'linkedin-oauth2', '~> 0.1.1'

Upvotes: 2

Related Questions