roblox_api/api/two_step_verification/
v1.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{Error, challenge::ActionType, client::Client};
4
5pub const URL: &str = "https://twostepverification.roblox.com/v1";
6
7// TODO: I don't know what `user_id` is for, as this api only seems to be used for the client only,
8// there's also currently no way to require id from Client, perhaps we should authenticate
9// on from_cookie method, and store the ClientDetails in the Client
10pub async fn authenticator_verify(
11    client: &mut Client,
12    user_id: u64,
13    code: &str,
14    action_type: ActionType,
15    server_challenge_id: &str,
16) -> Result<String, Error> {
17    #[derive(Serialize)]
18    struct Request<'a> {
19        #[serde(rename = "actionType")]
20        action_type: &'a str,
21        #[serde(rename = "challengeId")]
22        challenge_id: &'a str,
23        code: &'a str,
24    }
25
26    #[derive(Deserialize)]
27    struct Response {
28        #[serde(rename = "verificationToken")]
29        verification_token: String,
30    }
31
32    let result = client
33        .requestor
34        .client
35        .post(format!(
36            "{URL}/users/{user_id}/challenges/authenticator/verify"
37        ))
38        .headers(client.requestor.default_headers.clone())
39        .json(&Request {
40            action_type: &action_type.to_string(),
41            challenge_id: server_challenge_id,
42            code,
43        })
44        .send()
45        .await;
46
47    let response = client.validate_response(result).await?;
48    let result = client.requestor.parse_json::<Response>(response).await?;
49
50    Ok(result.verification_token)
51}