Skip to content

Instantly share code, notes, and snippets.

@celine-m-s
Created November 24, 2015 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save celine-m-s/e3f393c9b0400d1b2fe0 to your computer and use it in GitHub Desktop.
Save celine-m-s/e3f393c9b0400d1b2fe0 to your computer and use it in GitHub Desktop.
client = get_client
positions = client.profile(:fields => ["positions"])
positions.values # should return a hash with companies, dates and so on.
# This is what I did with Devise:
# devise.rb
config.omniauth :linkedin, ENV['OAUTH_LINKEDIN_ID'], ENV['OAUTH_LINKEDIN_SECRET'],
fields: %w(id email-address first-name last-name headline industry picture-url public-profile-url location num-connections positions)
# omniauth_callbacks_controller.rb
def self.provides_callback_for(provider)
class_eval %Q{
def #{provider}
@user = User.find_for_oauth(env["omniauth.auth"], current_user)
if @user.persisted?
handle_redirect("devise.#{provider}_uid", "#{provider}".capitalize)
else
session["devise.#{provider}_data"] = env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
}
end
[:facebook, :google_oauth2, :linkedin, :twitter].each do |provider|
provides_callback_for provider
end
def handle_redirect(_session_variable, kind)
# here we force the locale to the session locale so it siwtches to the correct locale
I18n.locale = session[:omniauth_login_locale] || I18n.default_locale
sign_in_and_redirect @user, event: :authentication
set_flash_message(:notice, :success, kind: kind) if is_navigational_format?
end
# user.rb
devise :omniauthable, :omniauth_providers => [:facebook, :google_oauth2, :linkedin, :twitter]
def self.find_for_oauth(auth, signed_in_resource = nil)
...
profile.positions = oauth.extra.raw_info.positions
...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment