Created
November 21, 2010 10:07
-
-
Save assimovt/708617 to your computer and use it in GitHub Desktop.
Railscast #236 extension with Fb_graph
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
# app/models/user.rb | |
def apply_omniauth(omniauth) | |
case omniauth['provider'] | |
when 'facebook' | |
self.apply_facebook(omniauth) | |
end | |
authentications.build(:provider => omniauth['provider'], :uid => omniauth['uid'], :token =>(omniauth['credentials']['token'] rescue nil)) | |
end | |
def facebook | |
@fb_user ||= FbGraph::User.me(self.authentications.find_by_provider('facebook').token) | |
end | |
protected | |
def apply_facebook(omniauth) | |
if (extra = omniauth['extra']['user_hash'] rescue false) | |
self.email = (extra['email'] rescue '') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment