11use reqwest:: cookie:: CookieStore ;
2- use std:: io:: { self , Write } ;
32use std:: str:: FromStr ;
4- use url:: Url ;
5- pub use vrchatapi:: apis;
6- use vrchatapi:: models:: { EitherUserOrTwoFactor , TwoFactorAuthCode , TwoFactorEmailCode } ;
73
84#[ tokio:: main]
95async fn main ( ) {
10- let mut config = apis:: configuration:: Configuration :: default ( ) ;
6+ let mut config = :: vrchatapi :: apis:: configuration:: Configuration :: default ( ) ;
117 config. basic_auth = Some ( ( String :: from ( "username" ) , Some ( String :: from ( "password" ) ) ) ) ;
128 config
. user_agent =
Some ( String :: from ( "ExampleProgram/0.0.1 [email protected] " ) ) ; 139
@@ -17,64 +13,74 @@ async fn main() {
1713 . build ( )
1814 . unwrap ( ) ;
1915
20- match apis:: authentication_api:: get_current_user ( & config)
16+ match :: vrchatapi :: apis:: authentication_api:: get_current_user ( & config)
2117 . await
2218 . unwrap ( )
2319 {
24- vrchatapi:: models:: EitherUserOrTwoFactor :: CurrentUser ( me) => {
20+ :: vrchatapi:: models:: RegisterUserAccount200Response :: CurrentUser ( me) => {
2521 println ! ( "Username: {}" , me. username. unwrap( ) )
2622 }
27- vrchatapi:: models:: EitherUserOrTwoFactor :: RequiresTwoFactorAuth ( requires_auth) => {
23+ :: vrchatapi:: models:: RegisterUserAccount200Response :: RequiresTwoFactorAuth (
24+ requires_auth,
25+ ) => {
2826 if requires_auth
2927 . requires_two_factor_auth
30- . contains ( & String :: from ( "emailOtp" ) )
28+ . unwrap_or_default ( )
29+ . contains ( & :: vrchatapi:: models:: TwoFactorAuthType :: EmailOtp )
3130 {
3231 let code = read_user_input ( "Please enter your Email 2fa code: " ) ;
33- if let Err ( err) = apis:: authentication_api:: verify2_fa_email_code (
32+ if let Err ( err) = :: vrchatapi :: apis:: authentication_api:: verify2_fa_email_code (
3433 & config,
35- TwoFactorEmailCode :: new ( code) ,
34+ :: vrchatapi :: models :: TwoFactorEmailCode :: new ( code) ,
3635 )
3736 . await
3837 {
3938 eprintln ! ( "Error verifying 2FA email code: {}" , err) ;
4039 }
4140 } else {
4241 let code = read_user_input ( "Please enter your Authenticator 2fa code: " ) ;
43- if let Err ( err) =
44- apis:: authentication_api:: verify2_fa ( & config, TwoFactorAuthCode :: new ( code) )
45- . await
42+ if let Err ( err) = :: vrchatapi:: apis:: authentication_api:: verify2_fa (
43+ & config,
44+ :: vrchatapi:: models:: TwoFactorAuthCode :: new ( code) ,
45+ )
46+ . await
4647 {
4748 eprintln ! ( "Error verifying 2FA auth code: {}" , err) ;
4849 }
4950 }
5051 }
5152 }
5253
53- let user = apis:: authentication_api:: get_current_user ( & config)
54+ let user = :: vrchatapi :: apis:: authentication_api:: get_current_user ( & config)
5455 . await
5556 . unwrap ( ) ;
5657
5758 match user {
58- EitherUserOrTwoFactor :: CurrentUser ( user) => println ! ( "Current user: {}" , user. display_name) ,
59- EitherUserOrTwoFactor :: RequiresTwoFactorAuth ( _) => println ! ( "cookie invalid" ) ,
59+ :: vrchatapi:: models:: RegisterUserAccount200Response :: CurrentUser ( user) => {
60+ println ! ( "Current user: {}" , user. display_name)
61+ }
62+ :: vrchatapi:: models:: RegisterUserAccount200Response :: RequiresTwoFactorAuth ( _) => {
63+ println ! ( "cookie invalid" )
64+ }
6065 }
6166
6267 println ! (
6368 "Cookie:{}" ,
6469 cookie_store
65- . cookies( & Url :: from_str( "https://api.vrchat.cloud" ) . expect( "Url not okay" ) )
70+ . cookies( & url :: Url :: from_str( "https://api.vrchat.cloud" ) . expect( "Url not okay" ) )
6671 . expect( "Cookies not found" )
6772 . to_str( )
6873 . expect( "Cookies not valid string" )
6974 ) ;
7075}
7176
7277fn read_user_input ( prompt : & str ) -> String {
78+ use :: std:: io:: Write ;
7379 print ! ( "{}" , prompt) ;
74- io:: stdout ( ) . flush ( ) . expect ( "Failed to flush stdout" ) ;
80+ :: std :: io:: stdout ( ) . flush ( ) . expect ( "Failed to flush stdout" ) ;
7581
7682 let mut input = String :: new ( ) ;
77- io:: stdin ( )
83+ :: std :: io:: stdin ( )
7884 . read_line ( & mut input)
7985 . expect ( "Failed to read line" ) ;
8086
0 commit comments