-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathauth.py
161 lines (139 loc) · 4.87 KB
/
auth.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
import json
import logging
import urllib.parse
import uuid
import requests
import websocket
from squeaky_hinge_config import *
import recaptcha
def authenticate(phone_number):
logging.info(f"START authentication flow")
hinge_install_id = str(uuid.uuid4()).lower()
logging.info(f"Generated new Hinge install ID {hinge_install_id}")
logging.info(f"Using X-App-Version {hinge_android_package}")
logging.info(f"Using X-Device-Platform {hinge_apk_sha1sum}")
resp = requests.post(
"https://prod-api.hingeaws.net/identity/install",
headers={
"X-App-Version": hinge_app_version,
"X-Device-Platform": hinge_device_platform,
},
json={
"installId": hinge_install_id,
},
)
logging.info(
f"Invoked identity/install and got response code {resp.status_code} and body: {resp.text}"
)
if not resp.ok:
raise Exception(
f"got response code {resp.status_code} when registering Hinge installation ID"
)
logging.info(f"Using X-Android-Package {hinge_android_package}")
logging.info(f"Using X-Android-Cert {hinge_apk_sha1sum}")
logging.info(f"Using Firebase web API key {firebase_web_api_key}")
resp = requests.get(
"https://identitytoolkit.googleapis.com/v1/recaptchaParams",
headers={
"X-Android-Package": hinge_android_package,
"X-Android-Cert": hinge_apk_sha1sum,
},
params={
"alt": "json",
"key": firebase_web_api_key,
},
)
logging.info(
f"Invoked recaptchaParams and got response code {resp.status_code} and body: {resp.text}"
)
if not resp.ok:
raise Exception(
f"got response code {resp.status_code} when getting ReCAPTCHA parameters"
)
recaptcha_params = resp.json()
recaptcha_site_key = recaptcha_params["recaptchaSiteKey"]
logging.info(f"Got reCAPTCHA site key {recaptcha_site_key}")
recaptcha_token = recaptcha.get_token(recaptcha_site_key)
logging.info(f"Got reCAPTCHA token {recaptcha_token}")
logging.info(f"Using phone number {phone_number}")
resp = requests.post(
"https://www.googleapis.com/identitytoolkit/v3/relyingparty/sendVerificationCode",
headers={
"X-Android-Package": hinge_android_package,
"X-Android-Cert": hinge_apk_sha1sum,
},
json={
"phone_number": phone_number,
"recaptcha_token": recaptcha_token,
},
params={
"alt": "json",
"key": firebase_web_api_key,
},
)
logging.info(
f"Invoked sendVerificationCode and got response code {resp.status_code} and body: {resp.text}"
)
if not resp.ok:
raise Exception(f"got response code {resp.status_code} when sending SMS code")
sms_send_info = resp.json()
session_info = sms_send_info["sessionInfo"]
logging.info(f"Got session info {session_info}")
resp = requests.post(
"https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPhoneNumber",
headers={
"X-Android-Package": hinge_android_package,
"X-Android-Cert": hinge_apk_sha1sum,
},
json={
"sessionInfo": session_info,
"code": input(f"SMS code from {phone_number}: "),
},
params={
"alt": "json",
"key": firebase_web_api_key,
},
)
logging.info(
f"Invoked verifyPhoneNumber and got response code {resp.status_code} and body: {resp.text}"
)
if not resp.ok:
raise Exception(f"got response code {resp.status_code} when verifying SMS code")
sms_verify_info = resp.json()
sms_jwt = sms_verify_info["idToken"]
logging.info(f"Got SMS JWT {sms_jwt}")
resp = requests.post(
"https://prod-api.hingeaws.net/auth/sms",
headers={
"X-App-Version": hinge_app_version,
"X-Device-Platform": hinge_device_platform,
},
json={
"installId": hinge_install_id,
"token": sms_jwt,
},
)
logging.info(
f"Invoked auth/sms and got response code {resp.status_code} and body: {resp.text}"
)
if not resp.ok:
raise Exception(
f"got response code {resp.status_code} when fetching Hinge API token"
)
hinge_token_data = resp.json()
hinge_token = hinge_token_data["token"]
user_id = hinge_token_data["identityId"]
logging.info(f"Got Hinge token {hinge_token}")
logging.info(f"Got user ID {user_id}")
with open("hinge_creds.json", "w") as f:
json.dump(
{
"hinge_token": hinge_token,
"user_id": user_id,
"hinge_install_id": hinge_install_id,
},
f,
indent=2,
)
f.write("\n")
logging.info(f"SUCCESS authentication flow")