Skip to content

Instantly share code, notes, and snippets.

@kineticac
Created March 9, 2011 09:28
Show Gist options
  • Select an option

  • Save kineticac/861941 to your computer and use it in GitHub Desktop.

Select an option

Save kineticac/861941 to your computer and use it in GitHub Desktop.
A good way to create the authentication for Facebook
def apply_omniauth(omniauth, save_it = false)
case omniauth['provider']
when 'facebook'
self.apply_facebook(omniauth)
end
self.email = omniauth['user_info']['email'] if email.blank?
build_authentications(omniauth, save_it)
end
def build_authentications(omniauth, save_it = false)
auth_params = {:provider => omniauth['provider'], :uid => omniauth['uid'], :token =>(omniauth['credentials']['token'] rescue nil)}
if save_it
authentications.create!(auth_params)
else
authentications.build(auth_params)
end
end
def apply_omniauth!(omniauth)
apply_omniauth(omniauth, true)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment