Created
March 9, 2011 09:28
-
-
Save kineticac/861941 to your computer and use it in GitHub Desktop.
A good way to create the authentication for Facebook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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