Skip to content

Instantly share code, notes, and snippets.

@lorenzosinisi
Last active August 29, 2015 14:22
Show Gist options
  • Save lorenzosinisi/c49ad1ac0787c84d63b0 to your computer and use it in GitHub Desktop.
Save lorenzosinisi/c49ad1ac0787c84d63b0 to your computer and use it in GitHub Desktop.
Validate Google Login / Facebook Login
def self.is_valid_google?(google_id, user_token)
user = user_token.to_s
uri = URI('https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=' + user)
string = JSON.parse(Net::HTTP.get(uri))
error = string["error"] if string["error"].present?
if error
return false
elsif string["user_id"].present?
if string["user_id"] == google_id
true
else
false
end
else
false
end
end
def self.is_valid_facebook?(facebook_id, user_token)
user = user_token.to_s
uri = URI('https://graph.facebook.com/me?fields=id&access_token=' + user)
string = JSON.parse(Net::HTTP.get(uri))
error = string["error"]["message"] if string["error"].present?
if error
return false
elsif string["id"].present?
if string["id"] == facebook_id
true
else
false
end
else
false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment