mirror of
https://github.com/mii443/vrchatapi-rust.git
synced 2025-08-22 15:45:35 +00:00
@ -5,8 +5,10 @@ async fn main() {
|
|||||||
let mut config = apis::configuration::Configuration::default();
|
let mut config = apis::configuration::Configuration::default();
|
||||||
config.basic_auth = Some((String::from("username"), Some(String::from("password"))));
|
config.basic_auth = Some((String::from("username"), Some(String::from("password"))));
|
||||||
|
|
||||||
let me = apis::authentication_api::get_current_user(&config).await.unwrap();
|
match apis::authentication_api::get_current_user(&config).await.unwrap() {
|
||||||
println!("Username: {}", me.username.unwrap());
|
vrchatapi::models::EitherUserOrTwoFactor::CurrentUser(me) => println!("Username: {}", me.username.unwrap()),
|
||||||
|
vrchatapi::models::EitherUserOrTwoFactor::RequiresTwoFactorAuth(requires_auth) => println!("The Username requires Auth: {:?}", requires_auth.requires_two_factor_auth)
|
||||||
|
}
|
||||||
|
|
||||||
let online = apis::system_api::get_current_online_users(&config).await.unwrap();
|
let online = apis::system_api::get_current_online_users(&config).await.unwrap();
|
||||||
println!("Current Online Users: {}", online);
|
println!("Current Online Users: {}", online);
|
||||||
|
@ -30,5 +30,10 @@ sed -i 's/features = \["json", "multipart"\]/features = \["json", "cookies", "mu
|
|||||||
#Fix example
|
#Fix example
|
||||||
printf "\n[dev-dependencies]\ntokio = { version = '1', features = ['macros', 'rt-multi-thread'] }" >> Cargo.toml
|
printf "\n[dev-dependencies]\ntokio = { version = '1', features = ['macros', 'rt-multi-thread'] }" >> Cargo.toml
|
||||||
|
|
||||||
|
# https://github.com/vrchatapi/specification/issues/241
|
||||||
|
cat patches/2FA_Current_User.rs >> src/models/current_user.rs
|
||||||
|
sed -i 's/pub use self::current_user::CurrentUser;/pub use self::current_user::{EitherUserOrTwoFactor, CurrentUser};/g' src/models/mod.rs
|
||||||
|
sed -i 's/Result<models::CurrentUser, Error<GetCurrentUserError>>/Result<models::EitherUserOrTwoFactor, Error<GetCurrentUserError>>/g' src/apis/authentication_api.rs
|
||||||
|
|
||||||
cargo build
|
cargo build
|
||||||
cargo test
|
cargo test
|
||||||
|
12
patches/2FA_Current_User.rs
Normal file
12
patches/2FA_Current_User.rs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
pub enum EitherUserOrTwoFactor{
|
||||||
|
CurrentUser(CurrentUser),
|
||||||
|
RequiresTwoFactorAuth(RequiresTwoFactorAuth),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
|
||||||
|
pub struct RequiresTwoFactorAuth{
|
||||||
|
#[serde(rename = "requiresTwoFactorAuth")]
|
||||||
|
pub requires_two_factor_auth: Vec<String>
|
||||||
|
}
|
@ -147,7 +147,7 @@ pub async fn delete_user(configuration: &configuration::Configuration, user_id:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// This endpoint does the following two operations: 1) Checks if you are already logged in by looking for a valid `auth` cookie. If you are have a valid auth cookie then no additional auth-related actions are taken. If you are **not** logged in then it will log you in with the `Authorization` header and set the `auth` cookie. The `auth` cookie will only be sent once. 2) If logged in, this function will also return the CurrentUser object containing detailed information about the currently logged in user. The auth string after `Authorization: Basic {string}` is a base64-encoded string of the username and password, both individually url-encoded, and then joined with a colon. > base64(urlencode(username):urlencode(password)) **WARNING: Session Limit:** Each authentication with login credentials counts as a separate session, out of which you have a limited amount. Make sure to save and reuse the `auth` cookie if you are often restarting the program. The provided API libraries automatically save cookies during runtime, but does not persist during restart. While it can be fine to use username/password during development, expect in production to very fast run into the rate-limit and be temporarily blocked from making new sessions until older ones expire. The exact number of simultaneous sessions is unknown/undisclosed.
|
/// This endpoint does the following two operations: 1) Checks if you are already logged in by looking for a valid `auth` cookie. If you are have a valid auth cookie then no additional auth-related actions are taken. If you are **not** logged in then it will log you in with the `Authorization` header and set the `auth` cookie. The `auth` cookie will only be sent once. 2) If logged in, this function will also return the CurrentUser object containing detailed information about the currently logged in user. The auth string after `Authorization: Basic {string}` is a base64-encoded string of the username and password, both individually url-encoded, and then joined with a colon. > base64(urlencode(username):urlencode(password)) **WARNING: Session Limit:** Each authentication with login credentials counts as a separate session, out of which you have a limited amount. Make sure to save and reuse the `auth` cookie if you are often restarting the program. The provided API libraries automatically save cookies during runtime, but does not persist during restart. While it can be fine to use username/password during development, expect in production to very fast run into the rate-limit and be temporarily blocked from making new sessions until older ones expire. The exact number of simultaneous sessions is unknown/undisclosed.
|
||||||
pub async fn get_current_user(configuration: &configuration::Configuration, ) -> Result<models::CurrentUser, Error<GetCurrentUserError>> {
|
pub async fn get_current_user(configuration: &configuration::Configuration, ) -> Result<models::EitherUserOrTwoFactor, Error<GetCurrentUserError>> {
|
||||||
let local_var_configuration = configuration;
|
let local_var_configuration = configuration;
|
||||||
|
|
||||||
let local_var_client = &local_var_configuration.client;
|
let local_var_client = &local_var_configuration.client;
|
||||||
|
@ -222,3 +222,15 @@ impl CurrentUser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
pub enum EitherUserOrTwoFactor{
|
||||||
|
CurrentUser(CurrentUser),
|
||||||
|
RequiresTwoFactorAuth(RequiresTwoFactorAuth),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
|
||||||
|
pub struct RequiresTwoFactorAuth{
|
||||||
|
#[serde(rename = "requiresTwoFactorAuth")]
|
||||||
|
pub requires_two_factor_auth: Vec<String>
|
||||||
|
}
|
@ -45,7 +45,7 @@ pub use self::create_instance_request::CreateInstanceRequest;
|
|||||||
pub mod create_world_request;
|
pub mod create_world_request;
|
||||||
pub use self::create_world_request::CreateWorldRequest;
|
pub use self::create_world_request::CreateWorldRequest;
|
||||||
pub mod current_user;
|
pub mod current_user;
|
||||||
pub use self::current_user::CurrentUser;
|
pub use self::current_user::{EitherUserOrTwoFactor, CurrentUser};
|
||||||
pub mod current_user_presence;
|
pub mod current_user_presence;
|
||||||
pub use self::current_user_presence::CurrentUserPresence;
|
pub use self::current_user_presence::CurrentUserPresence;
|
||||||
pub mod deployment_group;
|
pub mod deployment_group;
|
||||||
|
Reference in New Issue
Block a user