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 #[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}