module Omniauth::MultipleProviders::AuthHashContainable
# Usage class ProviderUser
< ActiveRecord::Base
include Omniauth::MultipleProviders::AuthHashContainable
end
Public Instance Methods
update_by(auth)
click to toggle source
TODO use method_missing
# File lib/omniauth/multiple_providers/models/concerns/auth_hash_containable.rb, line 21 def update_by(auth) self.provider = auth['provider'] self.uid = auth['uid'] case auth['provider'] when 'twitter' update_by_twitter(auth) when 'facebook' update_by_facebook(auth) when 'github' update_by_github(auth) when 'google_oauth2' update_by_google_oauth2(auth) end self.save end
update_by_facebook(auth)
click to toggle source
# File lib/omniauth/multiple_providers/models/concerns/auth_hash_containable.rb, line 46 def update_by_facebook(auth) self.access_token = auth['credentials']['token'] self.expires_at = auth['credentials']['expires_at'] self.email = auth['info']['email'] self.name = auth['info']['name'] self.nickname = auth['info']['nickname'] self.image_path = auth['info']['image'] self.gender = auth['extra']['raw_info']['gender'] self.locale = auth['extra']['raw_info']['locale'] end
update_by_github(auth)
click to toggle source
# File lib/omniauth/multiple_providers/models/concerns/auth_hash_containable.rb, line 57 def update_by_github(auth) self.email = auth['info']['email'] self.name = auth['info']['name'] self.nickname = auth['info']['nickname'] self.image_path = auth['info']['image'] self.access_token = auth['credentials']['token'] self.secret = auth['credentials']['secret'] self.refresh_token = auth['credentials']['refresh_token'] self.expires_at = auth['credentials']['expires_at'] end
update_by_google_oauth2(auth)
click to toggle source
# File lib/omniauth/multiple_providers/models/concerns/auth_hash_containable.rb, line 68 def update_by_google_oauth2(auth) self.email = auth['info']['email'] self.name = auth['info']['name'] self.access_token = auth['credentials']['token'] self.refresh_token = auth['credentials']['refresh_token'] self.expires_at = auth['credentials']['expires_at'] self.image_path = auth['info']['image'] self.gender = auth['extra']['raw_info']['gender'] self.locale = auth['extra']['raw_info']['locale'] end
update_by_twitter(auth)
click to toggle source
USAGE: if you want customize, you just overwrite follow methods.
# File lib/omniauth/multiple_providers/models/concerns/auth_hash_containable.rb, line 38 def update_by_twitter(auth) self.access_token = auth['credentials']['token'] self.secret = auth['credentials']['secret'] self.name = auth['info']['nickname'] self.nickname = auth['info']['nickname'] self.image_path = auth['info']['image'] end