Skip to content

Instantly share code, notes, and snippets.

@orafaelfragoso
Created August 1, 2014 03:44
Show Gist options
  • Save orafaelfragoso/7859f3a877ee67d65eb7 to your computer and use it in GitHub Desktop.
Save orafaelfragoso/7859f3a877ee67d65eb7 to your computer and use it in GitHub Desktop.
class Identity < ActiveRecord::Base
belongs_to :member
def self.find_with_omniauth(info)
find_by provider: info[:provider], uid: info[:uid]
end
def self.create_with_omniauth(info)
create(uid: info[:uid], provider: info[:provider], oauth_token: info[:oauth_token], oauth_expires_at: info[:oauth_expires_at], oauth_secret: info[:oauth_secret])
end
def self.filter_auth_hash(auth)
token = {}
# Facebook Filter
if auth.provider == "facebook"
token[:uid] = auth.uid
token[:provider] = auth.provider
token[:oauth_token] = auth.credentials.token
token[:oauth_expires_at] = Time.at(auth.credentials.expires_at.to_i)
token[:oauth_secret] = nil
end
if auth.provider == "linkedin"
token[:uid] = auth.uid
token[:provider] = auth.provider
token[:oauth_token] = auth.credentials.token
token[:oauth_secret] = auth.credentials.secret
token[:oauth_expires_at] = Time.at(auth.extra.access_token.params[:oauth_expires_in].to_i)
end
token
end
def update_oauth_token(info)
update_attributes(:oauth_token => info[:oauth_token], :oauth_expires_at => info[:oauth_expires_at], :oauth_secret => info[:oauth_secret])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment