Skip to content

Commit d5b5d6f

Browse files
authored
Include 2FA verification in getting started (#3)
* users_api is never used * Include 2FA verification in getting started
1 parent ea85fa8 commit d5b5d6f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ Below is an example on how to login to the API and fetch your own user informati
2828
```python
2929
# Step 1. We begin with creating a Configuration, which contains the username and password for authentication.
3030
import vrchatapi
31-
from vrchatapi.api import authentication_api, users_api
31+
from vrchatapi.api import authentication_api
32+
from vrchatapi.exceptions import UnauthorizedException
33+
from vrchatapi.model.two_factor_auth_code import TwoFactorAuthCode
3234

3335
configuration = vrchatapi.Configuration(
3436
username = 'username',
@@ -47,9 +49,17 @@ with vrchatapi.ApiClient(configuration) as api_client:
4749
try:
4850
# Step 3. Calling getCurrentUser on Authentication API logs you in if the user isn't already logged in.
4951
current_user = auth_api.get_current_user()
50-
print("Logged in as:", current_user.display_name)
52+
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: ")))
56+
current_user = auth_api.get_current_user()
57+
else:
58+
print("Exception when calling API: %s\n", e)
5159
except vrchatapi.ApiException as e:
5260
print("Exception when calling API: %s\n", e)
61+
62+
print("Logged in as:", current_user.display_name)
5363
```
5464

5565
See [example.py](https://github.com/vrchatapi/vrchatapi-python/blob/main/example.py) for more example usage on getting started.

0 commit comments

Comments
 (0)