Skip to content

Commit

Permalink
Fix telnyx auth api response parsing
Browse files Browse the repository at this point in the history
This is clearly a terrible bug that would authenticate anyone regardles
of if they input the correct code. I'm not sure if the API changed out
from under me, or more likley I templated this in and didn't follow up
to finish it.
  • Loading branch information
jkilpatr committed Sep 18, 2024
1 parent 6a705db commit d525801
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion rita_client_registration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,13 @@ pub struct TelnyxSmsAuthCheck {
code: String,
}

/// Response code is either accepted or rejected
#[derive(Debug, Deserialize)]
pub struct TelnyxSmsAuthResponse {
pub phone_number: PhoneNumber,
pub response_code: String,
}

/// Posts to the validation endpoint with the code, will return success if the code
/// is the same as the one sent to the user
pub async fn check_sms_auth_result(
Expand All @@ -316,6 +323,7 @@ pub async fn check_sms_auth_result(
number
);


let client = awc::Client::default();
match client
.post(check_url)
Expand All @@ -326,7 +334,14 @@ pub async fn check_sms_auth_result(
})
.await
{
Ok(a) => Ok(a.status().is_success()),
Ok(a) => {
let response = a.json::<TelnyxSmsAuthResponse>().await?;
if response.response_code == "accepted" {
Ok(true)
} else {
Ok(false)
}
},
Err(e) => {
error!("Failed to verify code with {:?}", e);
Err(e.into())
Expand Down

0 comments on commit d525801

Please sign in to comment.