Skip to content

Commit 2a317e3

Browse files
author
Yuu Kashima
authored
Merge pull request #1 from elliottcarlson/master
Add Google Auth
2 parents 8973386 + b4b052c commit 2a317e3

File tree

3 files changed

+71
-20
lines changed

3 files changed

+71
-20
lines changed

README.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,34 @@
66

77
## Demo
88

9-
$ python2 main.py --debug -u tejado -p 1234 --location "New York, Washington Square"
10-
[!] DEBUG mode on
9+
$ python main.py -a "ptc" -u "username" -p "password" -l "New York, Washington Square"
1110
[!] Your given location: Washington Square, Greenwich, NY 12834, USA
1211
[!] lat/long/alt: 43.0909305 -73.4989367 0.0
13-
[!] login for: tejado
14-
[+] RPC Session Token: TGT-899360-gFKDueEjBcKX4G ...
15-
[+] Received API endpoint: https://pgorelease.nianticlabs.com/plfe/401/rpc
12+
[!] PTC login for: sublimnl
13+
[+] RPC Session Token: TGT-842594-vsfLBEELnSrF ...
14+
[+] Received API endpoint: https://pgorelease.nianticlabs.com/plfe/94/rpc
1615
[+] Login successful
17-
[+] Username: tejado
18-
[+] You are playing Pokemon Go since: 2016-07-13 08:10:20
16+
[+] Username: username
17+
[+] You are playing Pokemon Go since: 2016-07-14 00:05:32
1918
[+] Poke Storage: 250
2019
[+] Item Storage: 350
2120
[+] POKECOIN: 0
22-
[+] STARDUST: 600
21+
[+] STARDUST: 300
22+
23+
$ python main.py -a "google" -u "[email protected]" -p "password" -l "New York, Washington Square"
24+
[!] Your given location: Washington Square, Greenwich, NY 12834, USA
25+
[!] lat/long/alt: 43.0909305 -73.4989367 0.0
26+
[!] Google login for: [email protected]
27+
[+] RPC Session Token: eyJhbGciOiJSUzI1NiIsImt ...
28+
[+] Received API endpoint: https://pgorelease.nianticlabs.com/plfe/490/rpc
29+
[+] Login successful
30+
[+] Username: <nickname>
31+
[+] You are playing Pokemon Go since: 2016-07-12 20:59:39
32+
[+] Poke Storage: 250
33+
[+] Item Storage: 350
34+
[+] POKECOIN: 0
35+
[+] STARDUST: 100
36+
2337

2438
## Credits
2539
Thanks a lot to [Mila432](https://github.com/Mila432/Pokemon_Go_API) !

main.py

100644100755
Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
#!/usr/bin/env python
12
import requests
23
import re
34
import struct
45
import json
56
import argparse
67
import pokemon_pb2
78

9+
from gpsoauth import perform_master_login, perform_oauth
810
from datetime import datetime
911
from geopy.geocoders import GoogleV3
1012
from requests.packages.urllib3.exceptions import InsecureRequestWarning
@@ -26,6 +28,11 @@
2628
COORDS_LONGITUDE = 0
2729
COORDS_ALTITUDE = 0
2830

31+
ANDROID_ID = '9774d56d682e549c'
32+
SERVICE= 'audience:server:client_id:848232511240-7so421jotr2609rmqakceuu1luuq0ptb.apps.googleusercontent.com'
33+
APP = 'com.nianticlabs.pokemongo'
34+
CLIENT_SIG = '321187995bc7cdc2b5fc91b11a96e2baa8602c62'
35+
2936
def f2i(float):
3037
return struct.unpack('<Q', struct.pack('<d', float))[0]
3138

@@ -52,7 +59,7 @@ def set_location_coords(lat, long, alt):
5259
def get_location_coords():
5360
return (COORDS_LATITUDE, COORDS_LONGITUDE, COORDS_ALTITUDE)
5461

55-
def api_req(api_endpoint, access_token, req):
62+
def api_req(service, api_endpoint, access_token, req):
5663
try:
5764
p_req = pokemon_pb2.RequestEnvelop()
5865
p_req.unknown1 = 2
@@ -63,7 +70,7 @@ def api_req(api_endpoint, access_token, req):
6370
p_req.latitude, p_req.longitude, p_req.altitude = get_location_coords()
6471

6572
p_req.unknown12 = 989
66-
p_req.auth.provider = 'ptc'
73+
p_req.auth.provider = service
6774
p_req.auth.token.contents = access_token
6875
p_req.auth.token.unknown13 = 59
6976
protobuf = p_req.SerializeToString()
@@ -79,7 +86,7 @@ def api_req(api_endpoint, access_token, req):
7986
return None
8087

8188

82-
def get_api_endpoint(access_token):
89+
def get_api_endpoint(service, access_token):
8390
req = pokemon_pb2.RequestEnvelop()
8491

8592
req1 = req.requests.add()
@@ -94,25 +101,33 @@ def get_api_endpoint(access_token):
94101
req5.type = 5
95102
req5.message.unknown4 = "4a2e9bc330dae60e7b74fc85b98868ab4700802e"
96103

97-
p_ret = api_req(API_URL, access_token, req.requests)
104+
p_ret = api_req(service, API_URL, access_token, req.requests)
98105

99106
try:
100107
return ('https://%s/rpc' % p_ret.api_url)
101108
except:
102109
return None
103110

104111

105-
def get_profile(api_endpoint, access_token):
112+
def get_profile(service, api_endpoint, access_token):
106113
req = pokemon_pb2.RequestEnvelop()
107114

108115
req1 = req.requests.add()
109116
req1.type = 2
110117

111-
return api_req(api_endpoint, access_token, req.requests)
118+
return api_req(service, api_endpoint, access_token, req.requests)
119+
120+
121+
def login_google(username, password):
122+
print('[!] Google login for: {}'.format(username))
123+
r1 = perform_master_login(username, password, ANDROID_ID)
124+
r2 = perform_oauth(username, r1.get('Token', ''), ANDROID_ID, SERVICE, APP,
125+
CLIENT_SIG)
112126

127+
return r2.get('Auth') # access token
113128

114129
def login_ptc(username, password):
115-
print('[!] login for: {}'.format(username))
130+
print('[!] PTC login for: {}'.format(username))
116131
head = {'User-Agent': 'niantic'}
117132
r = SESSION.get(LOGIN_URL, headers=head)
118133
jdata = json.loads(r.content)
@@ -149,14 +164,20 @@ def login_ptc(username, password):
149164

150165
def main():
151166
parser = argparse.ArgumentParser()
152-
parser.add_argument("-u", "--username", help="PTC Username", required=True)
153-
parser.add_argument("-p", "--password", help="PTC Password", required=True)
167+
parser.add_argument("-a", "--auth_service", help="Auth Service",
168+
required=True)
169+
parser.add_argument("-u", "--username", help="Username", required=True)
170+
parser.add_argument("-p", "--password", help="Password", required=True)
154171
parser.add_argument("-l", "--location", help="Location", required=True)
155172
parser.add_argument("-d", "--debug", help="Debug Mode", action='store_true')
156173
parser.add_argument("-s", "--client_secret", help="PTC Client Secret")
157174
parser.set_defaults(DEBUG=True)
158175
args = parser.parse_args()
159176

177+
if args.auth_service not in ['ptc', 'google']:
178+
print('[!] Invalid Auth service specified')
179+
return
180+
160181
if args.debug:
161182
global DEBUG
162183
DEBUG = True
@@ -168,19 +189,23 @@ def main():
168189

169190
set_location(args.location)
170191

171-
access_token = login_ptc(args.username, args.password)
192+
if args.auth_service == 'ptc':
193+
access_token = login_ptc(args.username, args.password)
194+
else:
195+
access_token = login_google(args.username, args.password)
196+
172197
if access_token is None:
173198
print('[-] Wrong username/password')
174199
return
175200
print('[+] RPC Session Token: {} ...'.format(access_token[:25]))
176201

177-
api_endpoint = get_api_endpoint(access_token)
202+
api_endpoint = get_api_endpoint(args.auth_service, access_token)
178203
if api_endpoint is None:
179204
print('[-] RPC server offline')
180205
return
181206
print('[+] Received API endpoint: {}'.format(api_endpoint))
182207

183-
profile = get_profile(api_endpoint, access_token)
208+
profile = get_profile(args.auth_service, api_endpoint, access_token)
184209
if profile is not None:
185210
print('[+] Login successful')
186211

requirements.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
cffi==1.7.0
2+
cryptography==1.4
3+
enum34==1.1.6
14
geopy==1.11.0
5+
gpsoauth==0.3.0
6+
idna==2.1
7+
ipaddress==1.0.16
8+
ndg-httpsclient==0.4.1
29
protobuf==2.6.1
10+
pyasn1==0.1.9
11+
pycparser==2.14
12+
pycryptodomex==3.4.2
13+
pyOpenSSL==16.0.0
314
requests==2.10.0
15+
six==1.10.0

0 commit comments

Comments
 (0)