Skip to content

Instantly share code, notes, and snippets.

@markoa
Created August 17, 2011 14:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markoa/1151655 to your computer and use it in GitHub Desktop.
Save markoa/1151655 to your computer and use it in GitHub Desktop.
Saving LinkedIn OAuth data in a callback action (Rails controller, Devise, Omniauth).
# in your routes.rb:
# devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
#
# and view:
# link_to("Connect to LinkedIn", user_omniauth_authorize_path(:linked_in))
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def linkedin
omniauth_hash = env["omniauth.auth"]
current_user.create_linkedin_connection(
:token => omniauth_hash["extra"]["access_token"].token,
:secret => omniauth_hash["extra"]["access_token"].secret,
:uid => omniauth_hash["uid"]
)
redirect_to root_path, :notice => "You've successfully connected your LinkedIn account."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment