Skip to content

Commit b1f02f4

Browse files
authored
Add 2fa compliance (#12)
* Add 2fa * Apply Changes
1 parent 4294b4b commit b1f02f4

6 files changed

Lines changed: 35 additions & 4 deletions

File tree

examples/online.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ async fn main() {
55
let mut config = apis::configuration::Configuration::default();
66
config.basic_auth = Some((String::from("username"), Some(String::from("password"))));
77

8-
let me = apis::authentication_api::get_current_user(&config).await.unwrap();
9-
println!("Username: {}", me.username.unwrap());
8+
match apis::authentication_api::get_current_user(&config).await.unwrap() {
9+
vrchatapi::models::EitherUserOrTwoFactor::CurrentUser(me) => println!("Username: {}", me.username.unwrap()),
10+
vrchatapi::models::EitherUserOrTwoFactor::RequiresTwoFactorAuth(requires_auth) => println!("The Username requires Auth: {:?}", requires_auth.requires_two_factor_auth)
11+
}
1012

1113
let online = apis::system_api::get_current_online_users(&config).await.unwrap();
1214
println!("Current Online Users: {}", online);

generate.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,10 @@ sed -i 's/features = \["json", "multipart"\]/features = \["json", "cookies", "mu
3030
#Fix example
3131
printf "\n[dev-dependencies]\ntokio = { version = '1', features = ['macros', 'rt-multi-thread'] }" >> Cargo.toml
3232

33+
# https://github.com/vrchatapi/specification/issues/241
34+
cat patches/2FA_Current_User.rs >> src/models/current_user.rs
35+
sed -i 's/pub use self::current_user::CurrentUser;/pub use self::current_user::{EitherUserOrTwoFactor, CurrentUser};/g' src/models/mod.rs
36+
sed -i 's/Result<models::CurrentUser, Error<GetCurrentUserError>>/Result<models::EitherUserOrTwoFactor, Error<GetCurrentUserError>>/g' src/apis/authentication_api.rs
37+
3338
cargo build
3439
cargo test

patches/2FA_Current_User.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#[derive(Serialize, Deserialize)]
2+
#[serde(untagged)]
3+
pub enum EitherUserOrTwoFactor{
4+
CurrentUser(CurrentUser),
5+
RequiresTwoFactorAuth(RequiresTwoFactorAuth),
6+
}
7+
8+
#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
9+
pub struct RequiresTwoFactorAuth{
10+
#[serde(rename = "requiresTwoFactorAuth")]
11+
pub requires_two_factor_auth: Vec<String>
12+
}

src/apis/authentication_api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ pub async fn delete_user(configuration: &configuration::Configuration, user_id:
147147
}
148148

149149
/// 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.
150-
pub async fn get_current_user(configuration: &configuration::Configuration, ) -> Result<models::CurrentUser, Error<GetCurrentUserError>> {
150+
pub async fn get_current_user(configuration: &configuration::Configuration, ) -> Result<models::EitherUserOrTwoFactor, Error<GetCurrentUserError>> {
151151
let local_var_configuration = configuration;
152152

153153
let local_var_client = &local_var_configuration.client;

src/models/current_user.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,15 @@ impl CurrentUser {
222222
}
223223
}
224224

225+
#[derive(Serialize, Deserialize)]
226+
#[serde(untagged)]
227+
pub enum EitherUserOrTwoFactor{
228+
CurrentUser(CurrentUser),
229+
RequiresTwoFactorAuth(RequiresTwoFactorAuth),
230+
}
231+
232+
#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
233+
pub struct RequiresTwoFactorAuth{
234+
#[serde(rename = "requiresTwoFactorAuth")]
235+
pub requires_two_factor_auth: Vec<String>
236+
}

src/models/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub use self::create_instance_request::CreateInstanceRequest;
4545
pub mod create_world_request;
4646
pub use self::create_world_request::CreateWorldRequest;
4747
pub mod current_user;
48-
pub use self::current_user::CurrentUser;
48+
pub use self::current_user::{EitherUserOrTwoFactor, CurrentUser};
4949
pub mod current_user_presence;
5050
pub use self::current_user_presence::CurrentUserPresence;
5151
pub mod deployment_group;

0 commit comments

Comments
 (0)