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    #[serde(rename_all = "camelCase")]
19    struct Request<'a> {
20        action_type: &'a str,
21        challenge_id: &'a str,
22        code: &'a str,
23    }
24
25    #[derive(Deserialize)]
26    #[serde(rename_all = "camelCase")]
27    struct Response {
28        verification_token: String,
29    }
30
31    let result = client
32        .requestor
33        .client
34        .post(format!(
35            "{URL}/users/{user_id}/challenges/authenticator/verify"
36        ))
37        .headers(client.requestor.default_headers.clone())
38        .json(&Request {
39            action_type: &action_type.to_string(),
40            challenge_id: server_challenge_id,
41            code,
42        })
43        .send()
44        .await;
45
46    let response = client.requestor.validate_response(result).await?;
47    let result = client.requestor.parse_json::<Response>(response).await?;
48
49    Ok(result.verification_token)
50}