-
Notifications
You must be signed in to change notification settings - Fork 8
/
api.py
188 lines (149 loc) · 7.57 KB
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#Simple script to explore how the new Grindr v4 web API works
import pygeohash
import requests
import json
import sys
import terminalqr
import time
import base64
import binascii
import uuid
import threading
import xmltodict
import random
from websocket import create_connection
# Fetching web client id
def fetchWebClientId():
url = 'https://grindr.mobi/v4/web-clients'
postData = {}
x = requests.post(url, data = postData)
data = json.loads(x.text)
return data["webClientId"]
#fetching auth token
def authtoken(id):
statuscode = 404
while statuscode == 404:
url = 'https://grindr.mobi/v4/authtokens/web/' + id
x = requests.get(url)
statuscode = x.status_code
time.sleep(1)
return json.loads(x.text)["authtoken"]
# generating qr code from web client id
def generateQr(id):
print("Generating QR code")
data = "grindrwebchat_" + id
terminalqr.drawqr(data)
print("url: https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=grindrwebchat_" + id)
# fetch user settings
def fetchSettings(authtoken):
url = 'https://grindr.mobi/v4/me/prefs/settings/web'
x = requests.get(url, headers={'authorization': 'Grindr3 ' + authtoken})
return json.loads(x.text)
# fetching all nearby profiles
def fetchProfiles(authtoken, _lat, _long, myType='false', online='false', faceOnly='false', photoOnly='false', notRecentlyChatted='false'):
geoHash = pygeohash.encode(_lat, _long, precision = 12)
url = 'https://grindr.mobi/v4/locations/' + geoHash + '/profiles?myType=' + myType + '&online=' + online + '&faceOnly=' + faceOnly + '&photoOnly=' + photoOnly + '¬RecentlyChatted=' + notRecentlyChatted
x = requests.get(url, headers={'authorization': 'Grindr3 ' + authtoken})
return json.loads(x.text)
# extracting user profile id
def getProfileId(authtoken):
_authtoken = authtoken.split(".")
_authtoken = _authtoken[1]
#adding a shit ton of padding
for i in range(len(authtoken), 400):
_authtoken += "="
data = base64.b64decode(_authtoken)
return json.loads(data)["profileId"]
# generating plain auth
def generatePlainAuth(authtoken):
auth = getProfileId(authtoken) + "@chat.grindr.com" + "\00" + getProfileId(authtoken) + "\00" + authtoken
_hex = binascii.b2a_base64(str.encode(auth), newline=False)
_hex = str(_hex)
_hex = _hex.replace("b'", "").replace("'", "")
return _hex
# perforiming a full login
def fullLogin():
webClientId = fetchWebClientId()
generateQr(webClientId)
return [str(authtoken(webClientId)), str(webClientId)]
# xmpp stuff (WIP)
class messageSocket:
def __init__(self, tokens, onmessage):
self.ws = create_connection("wss://chat.grindr.com:2443/ws-xmpp")
self.tokens = tokens
self.onmessage = onmessage
self.acks = 0
def authenticate(self):
print('<open to="chat.grindr.com" version="1.0" xmlns="urn:ietf:params:xml:ns:xmpp-framing"/>')
self.ws.send('<open to="chat.grindr.com" version="1.0" xmlns="urn:ietf:params:xml:ns:xmpp-framing"/>')
i = 1
while i:
#WS-XMPP STATE MACHINE
respons = self.ws.recv()
#print(respons + "\n-------------------------------------------------------------------------------------------------------------------")
if "features" in respons:
self.ws.send('<auth mechanism="PLAIN" xmlns="urn:ietf:params:xml:ns:xmpp-sasl">' + generatePlainAuth(self.tokens[0]) + '</auth>')
if "success" in respons:
self.ws.send('<open to="chat.grindr.com" version="1.0" xmlns="urn:ietf:params:xml:ns:xmpp-framing"/>')
self.ws.send('<iq id="_bind_auth_2" type="set" xmlns="jabber:client"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><resource>' + self.tokens[1] + '_web</resource></bind></iq>')
if "_bind_auth_2" in respons:
self.ws.send('<iq id="_session_auth_2" type="set" xmlns="jabber:client"><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></iq>')
self.ws.send('<iq from="' + getProfileId(self.tokens[0]) + '@chat.grindr.com/' + self.tokens[1] + '_web" id="' + str(uuid.uuid4()) + ':carbons" type="set" xmlns="jabber:client"><enable xmlns="urn:xmpp:carbons:2"/></iq>')
self.ws.send('<enable resume="false" xmlns="urn:xmpp:sm:3"/>')
self.ws.send('<presence xmlns="jabber:client"/>')
time.sleep(1)
self.ack()
if "r xmlns" in respons:
i = 0
if "failure" in respons:
return ""
#receive message
def ack(self):
#to avoid getting kicked for to many unacked messages
self.acks += 1
self.ws.send('<a h="' + str(self.acks) + '" xmlns="urn:xmpp:sm:3"/>')
def messageThread(self):
i = 2
while 1:
respons = self.ws.recv()
if respons:
respons = xmltodict.parse(respons)
if next(iter(respons)) == 'message':
self.ack()
try:
data = respons["message"]["body"]
data = json.loads(data)
if(data["type"] == "image"):
#generating image url
body = json.loads(data["body"])
imageUrl = "https://cdns.grindr.com/grindr/chat/" + body["imageHash"]
if("taps" in body["imageHash"]):
self.onmessage(imageUrl, data["sourceProfileId"], "tap")
else:
self.onmessage(imageUrl, data["sourceProfileId"], data["type"])
else:
self.onmessage(data["body"], data["sourceProfileId"], data["type"])
except:
pass
if next(iter(respons)) == 'presence':
self.ack()
def message(self, id, message):
s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"
p = "".join(random.sample(s, 16))
data = {"sourceProfileId":str(getProfileId(self.tokens[0])),"targetProfileId":str(id),"messageId":str(uuid.uuid1()),"sourceDisplayName":str(getProfileId(self.tokens[0])),"type":"text","timestamp":time.time(),"body":str(message)}
data = json.dumps(data)
data = data.replace('"', '"')
self.ws.send('<message from="' + getProfileId(self.tokens[0]) + '@chat.grindr.com" id="'+ p +'" to="' + str(id) + '@chat.grindr.com" type="chat" xmlns="jabber:client"><body>' + data + '</body></message>')
def tap(self, id, tapType):
body = '{\"imageHash\":\"taps/friendly.png\",\"imageType\":2,\"tapType\":0}'
if tapType == 1:
body = '{\"imageHash\":\"taps/hot.png\",\"imageType\":2,\"tapType\":1}'
if tapType == 1:
body = '{\"imageHash\":\"taps/looking.png\",\"imageType\":2,\"tapType\":2}'
data = {"sourceProfileId":str(getProfileId(self.tokens[0])),"targetProfileId":str(id),"messageId":str(uuid.uuid1()),"sourceDisplayName":str(getProfileId(self.tokens[0])),"type":"image","timestamp":time.time(),"body":str(body)}
data = json.dumps(data)
data = data.replace('"', '"')
self.ws.send('<message from="' + getProfileId(self.tokens[0]) + '@chat.grindr.com" id="U2ot8EBFwLRAw6U9" to="' + str(id) + '@chat.grindr.com" type="image" xmlns="jabber:client"><body>' + data + '</body></message>')
def start(self):
self.authenticate()
self.messageThread()