Skip to content

Instantly share code, notes, and snippets.

@modocache
Created September 17, 2012 02:20
Show Gist options
  • Save modocache/3735236 to your computer and use it in GitHub Desktop.
Save modocache/3735236 to your computer and use it in GitHub Desktop.
def android_login
token = params['token']
uri = URI.parse("https://www.googleapis.com")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
path = "/oauth2/v1/tokeninfo?access_token=#{token}"
resp = http.get(path)
data = JSON.parse(resp.body)
if resp.code == "200" && user = User.find_or_create_by_email(data['email'])
sign_in(:user, user)
session[:user_id] = user.id
end
redirect_to :root
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment