Repository URL to install this package:
|
Version:
4.0.0.pre.3 ▾
|
module Core
module Utils
# A client for accessing the Facebook Graph.
# Designed for account integration.
class FacebookGraph
def initialize(token)
@token = token
validate_configuration
end
def user
client.get('me', appsecret_proof: proof).parsed
rescue OAuth2::Error
raise Errors::TokenExchangeError, 'The token provided was invalid.'
end
private
def validate_configuration
unless Core.configuration.facebook_key
fail Errors::ConfigurationError, 'facebook_key is missing'
end
unless Core.configuration.facebook_secret
fail Errors::ConfigurationError, 'facebook_secret is missing'
end
fail Errors::ConfigurationError, 'token is missing' unless @token
end
def client
client = OAuth2::Client.new(Core.configuration.facebook_key,
Core.configuration.facebook_secret,
site: 'https://graph.facebook.com')
OAuth2::AccessToken.from_hash(client, access_token: @token)
end
def proof
OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA256.new,
Core.configuration.facebook_secret, @token)
end
end
end
end