Created
June 5, 2015 11:25
-
-
Save borewicz/175b3d85fe6834414354 to your computer and use it in GitHub Desktop.
login to Google+ using Android Client API - POC
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'net/http' | |
username = "USERNAME" | |
password = "PASSWORD" | |
def convToHash(text) | |
result = Hash.new | |
text.each_line do |line| | |
line = line.split('=') | |
result[line[0]] = line[1].to_s | |
end | |
result | |
end | |
def parameterize(params) | |
URI.escape(params.collect{|k,v| "#{k}=#{v}"}.join('&')) | |
end | |
def getToken(username, password) | |
uri = URI('https://android.clients.google.com/auth') | |
req = Net::HTTP::Post.new(uri) | |
req['User-Agent'] = "GoogleLoginService/1.3" | |
req.set_form_data({ | |
"accountType" => "HOSTED_OR_GOOGLE", | |
"Email" => username, | |
"add_account" => 1, | |
"Passwd" => password, | |
"service" => "ac2dm", | |
"source" => "android", | |
"androidId" => "31e0e7f6a1fa7484", | |
"lang" => "pl" | |
}) | |
res = Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http| | |
http.request(req) | |
end | |
convToHash(res.body)['Token'] | |
end | |
def getAccessToken(token, username) | |
scope = ['https://www.googleapis.com/auth/plus.me', 'https://www.googleapis.com/auth/plus.stream.read', 'https://www.googleapis.com/auth/plus.stream.write', 'https://www.googleapis.com/auth/plus.circles.write', 'https://www.googleapis.com/auth/plus.circles.read', 'https://www.googleapis.com/auth/plus.photos.readwrite'] | |
uri = URI('https://android.clients.google.com/auth') | |
requestData = parameterize({ | |
"device_country" => "pl", | |
"accountType" => "HOSTED_OR_GOOGLE", | |
"Email" => username, | |
"service" => "oauth2:" + scope.join('+'), | |
"source" => "android", | |
"app" => "com.google.android.gms", | |
"client_sig" => "38918a453d07199354f8b19af05ec6562ced5788", | |
"callerPkg" => "com.google.android.gms", | |
"callerSig" => "38918a453d07199354f8b19af05ec6562ced5788", | |
"Token" => token | |
}) | |
req = Net::HTTP::Post.new(uri) | |
req['User-Agent'] = "GoogleLoginService/1.3" | |
req.body = requestData | |
res = Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http| | |
http.request(req) | |
end | |
convToHash(res.body)['Auth'] | |
end | |
token = getToken(username, password) | |
auth = getAccessToken(token, username) | |
print auth |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment