New LinkedIn Permission Issues (Rails omniauth-linkedin gem)

I am using the omniauth-linkedin pearl for my rails application:

https://github.com/skorks/omniauth-linkedin

The new procedures and areas of LinkedIn permission request areas should be considered, but I have no success in getting email addresses or full profiles (anything other than default profile reviews).

Here is my omniauth.rb file:

Rails.application.config.middleware.use OmniAuth::Builder do provider :linkedin, ENV['LINKEDIN_KEY'], ENV['LINKEDIN_SECRET'], :scope => 'r_fullprofile r_emailaddress' end 

Requesting a full profile and email address starts with LinkedIn initially, before the user enters their credentials. However, area requests are lost after the user logs in, and only default profile view information is available.

I think my problem is with the need to specifically request these fields in the areas that I want, as mentioned on the gem page (https://github.com/skorks/omniauth-linkedin). However, I tried to add specific field requests to my omniauth.rb file without success (email field request below):

 Rails.application.config.middleware.use OmniAuth::Builder do provider :linkedin, ENV['LINKEDIN_KEY'], ENV['LINKEDIN_SECRET'], :scope => 'r_fullprofile+r_emailaddress', :fields => ["id", "email-address", "first-name", "last-name", "headline", "industry", "picture-url", "public-profile-url", "location", "positions", "educations"] end 

Apparently, I should request profile default fields in addition to non-default fields, such as email address, position and education, in order to access these last non-default fields.

LinkedIn email address should be simple, as it is not a structured object, for example, positions or education, and I believe that I do not have enough code for certain fields in positions and education that I want (I don’t know how I will write this and also would like to get some input from this). I am using my new API keys, so I'm not sure what the problem is. Do I need any special permission from LinkedIn? Help is appreciated! Thanks.

Also, here is the corresponding code for my controller:

 require 'linkedin' class AuthController < ApplicationController def auth client = LinkedIn::Client.new(ENV['LINKEDIN_KEY'], ENV['LINKEDIN_SECRET']) request_token = client.request_token(:oauth_callback => "http://#{request.host_with_port}/callback") session[:rtoken] = request_token.token session[:rsecret] = request_token.secret redirect_to client.request_token.authorize_url end def callback client = LinkedIn::Client.new(ENV['LINKEDIN_KEY'], ENV['LINKEDIN_SECRET']) if current_user.atoken.nil? && current_user.asecret.nil? pin = params[:oauth_verifier] atoken, asecret = client.authorize_from_request(session[:rtoken], session[:rsecret], pin) current_user.atoken = atoken current_user.asecret = asecret current_user.uid = client.profile(:fields => ["id"]).id flash.now[:success] = 'Signed in with LinkedIn.' elsif current_user.atoken && current_user.asecret client.authorize_from_access(current_user.atoken, current_user.asecret) flash.now[:success] = 'Signed in with LinkedIn.' end 
+4
source share
1 answer

Not sure if this is the most elegant solution, but it worked for me.

I just added a configuration with scope passed in request_token_path

 LINKEDIN_CONFIGURATION = { :site => 'https://api.linkedin.com', :authorize_path => '/uas/oauth/authenticate', :request_token_path =>'/uas/oauth/requestToken?scope=r_basicprofile+r_emailaddress+r_network+r_contactinfo', :access_token_path => '/uas/oauth/accessToken' } client = LinkedIn::Client.new(LINKEDIN_API_KEY, LINKEDIN_SECRET_KEY, LINKEDIN_CONFIGURATION ) 

and the rest of the code is the same.

Be sure to change the client constructor in the callback method.

+3
source

All Articles