Last active
August 29, 2015 14:22
-
-
Save lorenzosinisi/c49ad1ac0787c84d63b0 to your computer and use it in GitHub Desktop.
Validate Google Login / Facebook Login
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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