Move lib to root dir

This commit is contained in:
Jonathan Cooper 2026-02-01 17:36:22 -08:00
parent 88b21fc08d
commit 0d26e9326a
13 changed files with 2 additions and 1 deletions

64
src/client.rs Normal file
View file

@ -0,0 +1,64 @@
use serde::{Deserialize, Serialize};
use crate::error::SfAuthError;
const VALIDATION_URL: &str = "https://snazzyfellas.com/api/redirect/validate";
/// Request payload for validation API
#[derive(Debug, Serialize)]
struct ValidationRequest {
user_id: String,
key: String,
}
/// Response from validation API
#[derive(Debug, Deserialize)]
struct ValidationResponse {
valid: bool,
user_id: String,
}
/// Validates user credentials with the SF authentication server.
///
/// Makes a POST request to the validation endpoint with the user_id and key.
/// Returns `Ok(user_id)` if validation succeeds, or an error otherwise.
///
/// # Arguments
///
/// * `user_id` - The user ID to validate
/// * `key` - The authentication key to validate
///
/// # Errors
///
/// Returns an error if:
/// - The HTTP request fails
/// - The validation response indicates invalid credentials
/// - The returned user_id doesn't match the requested user_id
pub(crate) async fn validate_user(user_id: String, key: String) -> Result<String, SfAuthError> {
let client = reqwest::Client::new();
let request_payload = ValidationRequest {
user_id: user_id.clone(),
key,
};
let response = client
.post(VALIDATION_URL)
.json(&request_payload)
.send()
.await?;
let validation_response: ValidationResponse = response.json().await?;
// Check if validation succeeded
if !validation_response.valid {
return Err(SfAuthError::ValidationFailed);
}
// Verify that the returned user_id matches what we sent
if validation_response.user_id != user_id {
return Err(SfAuthError::UserIdMismatch);
}
Ok(validation_response.user_id)
}