Add instagram background implementation and generalize application for other identity providers
This commit is contained in:
+23
-4
@@ -13,7 +13,7 @@ class User
|
||||
property :oauth_expires_at
|
||||
property :auth_data
|
||||
|
||||
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :omniauthable, :omniauth_providers => [:facebook] #, :token_authenticatable , :registerable
|
||||
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :omniauthable, :omniauth_providers => [:facebook, :instagram] #, :token_authenticatable , :registerable
|
||||
|
||||
property :authentication_token
|
||||
|
||||
@@ -28,10 +28,11 @@ class User
|
||||
|
||||
view :by_authentication_token, key: :authentication_token
|
||||
view :by_email, key: :email
|
||||
view :by_facebook, key: [:provider, :uid]
|
||||
view :by_facebook, key: [:provider, :uid] #DEPRICATE on successful change to by_provider
|
||||
view :by_provider, key: [:provider, :uid]
|
||||
|
||||
def self.find_for_facebook_oauth(auth_data, user)
|
||||
user = database.view(self.by_facebook(key: [auth_data.provider, auth_data.uid], limit: 1)).first
|
||||
def self.find_for_oauth(auth_data, user)
|
||||
user = database.view(self.by_provider(key: [auth_data.provider, auth_data.uid], limit: 1)).first
|
||||
|
||||
user || create(
|
||||
provider: auth_data.provider,
|
||||
@@ -49,6 +50,24 @@ class User
|
||||
uid
|
||||
end
|
||||
|
||||
def provider_info
|
||||
case provider.to_sym
|
||||
when :facebook then {}
|
||||
when :instagram
|
||||
uri = URI.parse("https://api.instagram.com/v1/users/#{uid}?access_token=#{auth_data['credentials']['token']}")
|
||||
JSON.parse(Net::HTTP.get(uri)) rescue {ok: false, error: 'cannot_parse_response'}
|
||||
else
|
||||
{ok: false, error: 'provider_unknown'}
|
||||
end
|
||||
end
|
||||
|
||||
def avatar
|
||||
case provider.to_sym
|
||||
when :facebook then "http://graph.facebook.com/#{uid}/picture?type=square"
|
||||
when :instagram then auth_data['info'].try(:[], 'image')
|
||||
end
|
||||
end
|
||||
|
||||
def self.from_omniauth(auth)
|
||||
#binding.pry
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user