New LinkedIn Permissions Problems (Rails omniauth-linkedin gem)

authentication, linkedin-api, omniauth, ruby-on-rails

Solution

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

I just added the config with the scope passed in the 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 as well.

Problem

I'm using the omniauth-linkedin gem for my rails application: https://github.com/skorks/omniauth-linkedin It should be taking into account new LinkedIn permissions request procedures and scopes, but I am not having success obtaining either email addresses or full profiles (anything other than the default profile overviews). 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 ``` The full profile and email address request are going through to LinkedIn initially, before the user enters her/his credentials. However, the scope requests are lost once the user signs in, and only the default profile overview information is accessible. I think my problem has something to do with having to specifically request those fields within the scopes that I want, as is mentioned on the gem page (https://github.com/skorks/omniauth-linkedin). Still, I have tried adding specific field requests to my omniauth.rb file with no 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 am supposed to request the default fields of the profile overview in addition to the non-default fields like email-address, positions, and educations in order to access these latter non-default fields. LinkedIn email-address should be straightforward, as it is not a structured object like positions or educations are, and I believe I am missing code for specific fields within positions and educations that I want (not sure how i would write that and would love some input on that as well). I am using my new API keys, so I'm not sure what the problem may be. Do I need some kind of special permission from LinkedIn? Help is appreciated! Thank you. Also, here is the relevant code for my auth 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 ```

Original source