roblox_api/api/two_step_verification/
v1.rs1use serde::{Deserialize, Serialize};
2
3use crate::{Error, challenge::ActionType, client::Client};
4
5pub const URL: &str = "https://twostepverification.roblox.com/v1";
6
7pub 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}