-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 2fa compliance #12
Conversation
da0d7f0
to
3e1f2d3
Compare
What about the existing code doesn't support 2FA? |
Previously, if you had 2fa, the response from vrchat would fail to serialise as a CurrentUser. This PR makes it way easier and way less jank to handle a 2fa-enabled user. Edit: Also see the mentioned specification issue, where you mentioned, that you handled this manually for the Dart api. |
3953ac0
to
04d6514
Compare
I have run into the same issue, leading to me write my own crude implementation, I would love to see this PR merged <3 pub use vrchatapi::apis;
fn main() {
let username =
std::env::var("VRCHAT_USERNAME").expect("Missing VRCHAT_USERNAME environment variable");
let password =
std::env::var("VRCHAT_PASSWORD").expect("Missing VRCHAT_PASSWORD environment variable");
let config = apis::configuration::Configuration {
basic_auth: Some((username, Some(password))),
user_agent: Some(
"Mozilla/5.0 (Windows NT 6.1; rv:40.0) Gecko/20100101 Firefox/40.0".to_string(),
),
..Default::default()
};
let me =
apis::authentication_api::get_current_user(&config).expect("Failed to get current user");
println!("Username: {:?}", me.username);
let online = apis::system_api::get_current_online_users(&config).unwrap();
println!("Current Online Users: {}", online);
} I get the following error with an account that has 2FA set up:
This PR would fix that Serialization error and would give a clear and consise way of dealing with unknown account states via a simple match. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rebase your PR to the latest commit.
I was just doing exactly that. |
Tested with this code: use std::io::BufRead;
pub use vrchatapi::{apis, models};
#[tokio::main]
async fn main() {
let username =
std::env::var("VRCHAT_USERNAME").expect("Missing VRCHAT_USERNAME environment variable");
let password =
std::env::var("VRCHAT_PASSWORD").expect("Missing VRCHAT_PASSWORD environment variable");
let config = apis::configuration::Configuration {
basic_auth: Some((username, Some(password))),
user_agent: Some(
"Mozilla/5.0 (Windows NT 6.1; rv:40.0) Gecko/20100101 Firefox/40.0".to_string(),
),
..Default::default()
};
let me = apis::authentication_api::get_current_user(&config)
.await
.expect("Failed to get current user");
match me {
vrchatapi::models::EitherUserOrTwoFactor::CurrentUser(me) => {
println!("Current User: {}", me.display_name);
}
vrchatapi::models::EitherUserOrTwoFactor::RequiresTwoFactorAuth(_two_factor_type) => {
// i should check here if its email or TOTP
let mut code = String::new();
let stdin = std::io::stdin();
stdin
.lock()
.read_line(&mut code)
.expect("Failed to read line");
let resp =
apis::authentication_api::verify2_fa(&config, models::TwoFactorAuthCode::new(code))
.await
.expect("Failed to verify 2FA");
if !resp.verified {
panic!("Failed to verify 2FA");
}
}
}
let online = apis::system_api::get_current_online_users(&config)
.await
.unwrap();
println!("Current Online Users: {}", online);
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vrchatapi/specification#241
Adds 2fa support to vrcapi.
The code has been adapted from a commit, from 9 months ago, where I edited source-code.
I adapted the code to the generate.sh file.
Due to issues with compilation and bash, I needed to add the extra lines