Skip to content

Commit f7a99a2

Browse files
authored
Readable Email 2FA Required error + updated example (#7)
* Remove patch code to create new patch * Include Email 2FA in 2FA Readable Patch * Include Email 2FA Verification in example
1 parent b0746de commit f7a99a2

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import vrchatapi
3131
from vrchatapi.api import authentication_api
3232
from vrchatapi.exceptions import UnauthorizedException
3333
from vrchatapi.models.two_factor_auth_code import TwoFactorAuthCode
34+
from vrchatapi.models.two_factor_email_code import TwoFactorEmailCode
3435

3536
configuration = vrchatapi.Configuration(
3637
username = 'username',
@@ -50,9 +51,13 @@ with vrchatapi.ApiClient(configuration) as api_client:
5051
# Step 3. Calling getCurrentUser on Authentication API logs you in if the user isn't already logged in.
5152
current_user = auth_api.get_current_user()
5253
except UnauthorizedException as e:
53-
if UnauthorizedException.status == 200:
54-
# Step 3.5. Calling verify2fa if the account has 2FA enabled
55-
auth_api.verify2_fa(two_factor_auth_code=TwoFactorAuthCode(input("2FA Code: ")))
54+
if e.status == 200:
55+
if "Email 2 Factor Authentication" in e.reason:
56+
# Step 3.5. Calling email verify2fa if the account has 2FA disabled
57+
auth_api.verify2_fa_email_code(two_factor_email_code=TwoFactorEmailCode(input("Email 2FA Code: ")))
58+
elif "2 Factor Authentication" in e.reason:
59+
# Step 3.5. Calling verify2fa if the account has 2FA enabled
60+
auth_api.verify2_fa(two_factor_auth_code=TwoFactorAuthCode(input("2FA Code: ")))
5661
current_user = auth_api.get_current_user()
5762
else:
5863
print("Exception when calling API: %s\n", e)

patches/error_2fa_verify_readable.patch

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
diff --git a/vrchatapi/rest.py b/vrchatapi/rest.py
2-
index aac58f3..703ae1b 100644
3-
--- a/vrchatapi/rest.py
4-
+++ b/vrchatapi/rest.py
5-
@@ -239,6 +239,10 @@ class RESTClientObject(object):
1+
diff --git a/./rest.py b/./restpatch.py
2+
index 3702266e..c19c578c 100644
3+
--- a/./rest.py
4+
+++ b/./restpatch.py
5+
@@ -245,6 +245,13 @@ class RESTClientObject(object):
66

77
raise ApiException(http_resp=r)
88

99
+ if re.match(b'{"\w{21}":\["totp","otp"]}', r.data) is not None:
1010
+ r.reason = "2 Factor Authentication verification is required"
1111
+ raise UnauthorizedException(http_resp=r)
12+
+ elif re.match(b'{"\w{21}":\["emailOtp"]}', r.data) is not None:
13+
+ r.reason = "Email 2 Factor Authentication verification is required"
14+
+ raise UnauthorizedException(http_resp=r)
1215
+
1316
return r
1417

vrchatapi/rest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ def request(self, method, url, query_params=None, headers=None,
248248
if re.match(b'{"\w{21}":\["totp","otp"]}', r.data) is not None:
249249
r.reason = "2 Factor Authentication verification is required"
250250
raise UnauthorizedException(http_resp=r)
251+
elif re.match(b'{"\w{21}":\["emailOtp"]}', r.data) is not None:
252+
r.reason = "Email 2 Factor Authentication verification is required"
253+
raise UnauthorizedException(http_resp=r)
251254

252255
return r
253256

0 commit comments

Comments
 (0)