Skip to content

Commit 5e06f62

Browse files
committed
adding captcha handling
1 parent 9c41989 commit 5e06f62

4 files changed

Lines changed: 21 additions & 14 deletions

File tree

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,16 @@ async def on_cancel():
3838
@c.event("on_timeout")
3939
async def on_timeout():
4040
print(f"Timeout")
41-
41+
42+
@c.event("on_captcha")
43+
async def on_captcha(captcha_data):
44+
# captcha_data contains captcha_sitekey, captcha_service (hcaptcha), captcha_rqdata and captcha_rqtoken
45+
print(f"Captcha!")
46+
captcha_key = ... # Solve captcha and get captcha_key
47+
return captcha_key
48+
4249
@c.event("on_error")
43-
async def on_timeout(exc, client):
50+
async def on_error(exc, client):
4451
print(f"Error: {exc.__class__.__name__}")
4552
if client.retries == 1:
4653
await client.run_task()

example.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33

44
c = RemoteAuthClient()
55

6-
76
@c.event("on_fingerprint")
87
async def on_fingerprint(data):
98
print(f"Fingerprint: {data}")
109
print(f"QrCode url: https://api.qrserver.com/v1/create-qr-code/?size=256x256&data={data}")
1110

12-
1311
@c.event("on_userdata")
1412
async def on_userdata(user):
1513
print(f"ID: {user.id}")
@@ -19,27 +17,29 @@ async def on_userdata(user):
1917
print(f"Name: {user.getName()}")
2018
print(f"Avatar URL: {user.getAvatarURL()}")
2119

22-
2320
@c.event("on_token")
2421
async def on_token(token):
2522
print(f"Token: {token}")
2623

27-
2824
@c.event("on_cancel")
2925
async def on_cancel():
3026
print(f"Auth canceled!")
3127

32-
3328
@c.event("on_timeout")
3429
async def on_timeout():
3530
print(f"Timeout")
3631

32+
@c.event("on_captcha")
33+
async def on_captcha(captcha_data):
34+
# captcha_data contains captcha_sitekey, captcha_service (hcaptcha), captcha_rqdata and captcha_rqtoken
35+
print(f"Captcha!")
36+
captcha_key = ... # Solve captcha and get captcha_key
37+
return captcha_key
3738

3839
@c.event("on_error")
39-
async def on_timeout(exc, client):
40+
async def on_error(exc, client):
4041
print(f"Error: {exc.__class__.__name__}")
4142
if client.retries == 1:
4243
await client.run_task()
4344

44-
4545
run(c.run())

remoteauthclient/remoteauthclient.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ async def _getToken(self, ticket: str, captcha_key: Optional[str]=None) -> Optio
119119
j = await resp.json()
120120
log.debug(f"Response code: {resp.status}")
121121
log.debug(f"Response body: {j}")
122-
# I'm not sure about captcha response
123-
if "encrypted_token" not in j and captcha_key is None:
124-
captcha_key = await self._event("captcha")
122+
if "encrypted_token" not in j and captcha_key is None and j.get("captcha_key") == "captcha-required":
123+
del j["captcha_key"]
124+
captcha_key = await self._event("captcha", captcha_data=j)
125125
if not captcha_key:
126126
return
127127
return await self._getToken(ticket, captcha_key)

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from setuptools import setup, find_packages
1+
from setuptools import setup
22
from os.path import join, dirname
33

44
requirements = [
@@ -9,7 +9,7 @@
99

1010
setup(
1111
name='remoteauthclient',
12-
version='1.3',
12+
version='1.4.0b',
1313
packages=["remoteauthclient"],
1414
long_description=open(join(dirname(__file__), 'README.md')).read(),
1515
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)