1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-08-06 06:02:40 +03:00

hCaptcha support

This commit is contained in:
Quentin Gliech
2024-05-11 14:39:12 +02:00
parent f9ae7ae313
commit 0e270d5449
6 changed files with 18 additions and 0 deletions

View File

@@ -132,6 +132,7 @@ pub fn captcha_config_from_config(
mas_config::CaptchaServiceKind::CloudflareTurnstile => { mas_config::CaptchaServiceKind::CloudflareTurnstile => {
mas_data_model::CaptchaService::CloudflareTurnstile mas_data_model::CaptchaService::CloudflareTurnstile
} }
mas_config::CaptchaServiceKind::HCaptcha => mas_data_model::CaptchaService::HCaptcha,
}; };
Ok(Some(mas_data_model::CaptchaConfig { Ok(Some(mas_data_model::CaptchaConfig {

View File

@@ -27,6 +27,10 @@ pub enum CaptchaServiceKind {
/// Use Cloudflare Turnstile /// Use Cloudflare Turnstile
#[serde(rename = "cloudflare_turnstile")] #[serde(rename = "cloudflare_turnstile")]
CloudflareTurnstile, CloudflareTurnstile,
/// Use ``HCaptcha``
#[serde(rename = "hcaptcha")]
HCaptcha,
} }
/// Configuration section to setup CAPTCHA protection on a few operations /// Configuration section to setup CAPTCHA protection on a few operations

View File

@@ -20,6 +20,7 @@ use url::Url;
pub enum CaptchaService { pub enum CaptchaService {
RecaptchaV2, RecaptchaV2,
CloudflareTurnstile, CloudflareTurnstile,
HCaptcha,
} }
/// Captcha configuration /// Captcha configuration

View File

@@ -33,6 +33,7 @@ impl Object for CaptchaConfig {
mas_data_model::CaptchaService::CloudflareTurnstile => { mas_data_model::CaptchaService::CloudflareTurnstile => {
"cloudflare_turnstile".into() "cloudflare_turnstile".into()
} }
mas_data_model::CaptchaService::HCaptcha => "hcaptcha".into(),
}), }),
Some("site_key") => Some(self.0.site_key.clone().into()), Some("site_key") => Some(self.0.site_key.clone().into()),
_ => None, _ => None,

View File

@@ -1995,6 +1995,13 @@
"enum": [ "enum": [
"cloudflare_turnstile" "cloudflare_turnstile"
] ]
},
{
"description": "Use ``HCaptcha``",
"type": "string",
"enum": [
"hcaptcha"
]
} }
] ]
}, },

View File

@@ -20,6 +20,8 @@ limitations under the License.
<div class="g-recaptcha {{ class }}" data-sitekey="{{ captcha.site_key }}"></div> <div class="g-recaptcha {{ class }}" data-sitekey="{{ captcha.site_key }}"></div>
{%- elif captcha.service == "cloudflare_turnstile" -%} {%- elif captcha.service == "cloudflare_turnstile" -%}
<div class="cf-turnstile {{ class }}" data-sitekey="{{ captcha.site_key }}"></div> <div class="cf-turnstile {{ class }}" data-sitekey="{{ captcha.site_key }}"></div>
{%- elif captcha.service == "hcaptcha" -%}
<div class="h-captcha {{ class }}" data-sitekey="{{ captcha.site_key }}"></div>
{%- else -%} {%- else -%}
{{ throw(message="Invalid captcha service setup") }} {{ throw(message="Invalid captcha service setup") }}
{%- endif %} {%- endif %}
@@ -32,6 +34,8 @@ limitations under the License.
<script src="https://www.google.com/recaptcha/api.js" async defer></script> <script src="https://www.google.com/recaptcha/api.js" async defer></script>
{%- elif captcha.service == "cloudflare_turnstile" -%} {%- elif captcha.service == "cloudflare_turnstile" -%}
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script> <script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
{%- elif captcha.service == "hcaptcha" -%}
<script src="https://js.hcaptcha.com/1/api.js" async defer></script>
{%- else -%} {%- else -%}
{{ throw(message="Invalid captcha service setup") }} {{ throw(message="Invalid captcha service setup") }}
{%- endif %} {%- endif %}