openauth_plugins/captcha/verify_handlers/
mod.rs1pub mod captchafox;
4pub mod cloudflare_turnstile;
5pub mod google_recaptcha;
6pub mod h_captcha;
7
8use super::options::{CaptchaOptions, CaptchaProvider};
9
10#[derive(Debug, thiserror::Error)]
11pub enum CaptchaVerifyError {
12 #[error("captcha service unavailable: {0}")]
13 ServiceUnavailable(String),
14}
15
16pub struct VerifyCaptchaInput<'a> {
17 pub options: &'a CaptchaOptions,
18 pub captcha_response: &'a str,
19 pub remote_ip: Option<String>,
20}
21
22pub async fn verify_captcha(input: VerifyCaptchaInput<'_>) -> Result<bool, CaptchaVerifyError> {
23 match input.options.provider {
24 CaptchaProvider::CloudflareTurnstile => {
25 cloudflare_turnstile::verify(input.options, input.captcha_response, input.remote_ip)
26 .await
27 }
28 CaptchaProvider::GoogleRecaptcha => {
29 google_recaptcha::verify(input.options, input.captcha_response, input.remote_ip).await
30 }
31 CaptchaProvider::HCaptcha => {
32 h_captcha::verify(input.options, input.captcha_response, input.remote_ip).await
33 }
34 CaptchaProvider::CaptchaFox => {
35 captchafox::verify(input.options, input.captcha_response, input.remote_ip).await
36 }
37 }
38}
39
40fn service_unavailable(error: impl ToString) -> CaptchaVerifyError {
41 CaptchaVerifyError::ServiceUnavailable(error.to_string())
42}