You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-08-06 06:02:40 +03:00
Cloudflare Turnstile support
This commit is contained in:
@@ -129,6 +129,9 @@ pub fn captcha_config_from_config(
|
|||||||
|
|
||||||
let service = match service {
|
let service = match service {
|
||||||
mas_config::CaptchaServiceKind::RecaptchaV2 => mas_data_model::CaptchaService::RecaptchaV2,
|
mas_config::CaptchaServiceKind::RecaptchaV2 => mas_data_model::CaptchaService::RecaptchaV2,
|
||||||
|
mas_config::CaptchaServiceKind::CloudflareTurnstile => {
|
||||||
|
mas_data_model::CaptchaService::CloudflareTurnstile
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Some(mas_data_model::CaptchaConfig {
|
Ok(Some(mas_data_model::CaptchaConfig {
|
||||||
|
@@ -23,6 +23,10 @@ pub enum CaptchaServiceKind {
|
|||||||
/// Use Google's reCAPTCHA v2 API
|
/// Use Google's reCAPTCHA v2 API
|
||||||
#[serde(rename = "recaptcha_v2")]
|
#[serde(rename = "recaptcha_v2")]
|
||||||
RecaptchaV2,
|
RecaptchaV2,
|
||||||
|
|
||||||
|
/// Use Cloudflare Turnstile
|
||||||
|
#[serde(rename = "cloudflare_turnstile")]
|
||||||
|
CloudflareTurnstile,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Configuration section to setup CAPTCHA protection on a few operations
|
/// Configuration section to setup CAPTCHA protection on a few operations
|
||||||
|
@@ -19,6 +19,7 @@ use url::Url;
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum CaptchaService {
|
pub enum CaptchaService {
|
||||||
RecaptchaV2,
|
RecaptchaV2,
|
||||||
|
CloudflareTurnstile,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Captcha configuration
|
/// Captcha configuration
|
||||||
|
@@ -30,6 +30,9 @@ impl Object for CaptchaConfig {
|
|||||||
match key.as_str() {
|
match key.as_str() {
|
||||||
Some("service") => Some(match &self.0.service {
|
Some("service") => Some(match &self.0.service {
|
||||||
mas_data_model::CaptchaService::RecaptchaV2 => "recaptcha_v2".into(),
|
mas_data_model::CaptchaService::RecaptchaV2 => "recaptcha_v2".into(),
|
||||||
|
mas_data_model::CaptchaService::CloudflareTurnstile => {
|
||||||
|
"cloudflare_turnstile".into()
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
Some("site_key") => Some(self.0.site_key.clone().into()),
|
Some("site_key") => Some(self.0.site_key.clone().into()),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@@ -1988,6 +1988,13 @@
|
|||||||
"enum": [
|
"enum": [
|
||||||
"recaptcha_v2"
|
"recaptcha_v2"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Use Cloudflare Turnstile",
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"cloudflare_turnstile"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@@ -14,10 +14,12 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
#}
|
#}
|
||||||
|
|
||||||
{% macro form() -%}
|
{% macro form(class="") -%}
|
||||||
{%- if captcha|default(False) -%}
|
{%- if captcha|default(False) -%}
|
||||||
{%- if captcha.service == "recaptcha_v2" -%}
|
{%- if captcha.service == "recaptcha_v2" -%}
|
||||||
<div class="g-recaptcha" data-sitekey="{{ captcha.site_key }}"></div>
|
<div class="g-recaptcha {{ class }}" data-sitekey="{{ captcha.site_key }}"></div>
|
||||||
|
{%- elif captcha.service == "cloudflare_turnstile" -%}
|
||||||
|
<div class="cf-turnstile {{ class }}" data-sitekey="{{ captcha.site_key }}"></div>
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
{{ throw(message="Invalid captcha service setup") }}
|
{{ throw(message="Invalid captcha service setup") }}
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
@@ -28,6 +30,8 @@ limitations under the License.
|
|||||||
{%- if captcha|default(False) -%}
|
{%- if captcha|default(False) -%}
|
||||||
{%- if captcha.service == "recaptcha_v2" -%}
|
{%- if captcha.service == "recaptcha_v2" -%}
|
||||||
<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" -%}
|
||||||
|
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
{{ throw(message="Invalid captcha service setup") }}
|
{{ throw(message="Invalid captcha service setup") }}
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
@@ -69,7 +69,7 @@ limitations under the License.
|
|||||||
{% endcall %}
|
{% endcall %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{{ captcha.form() }}
|
{{ captcha.form(class="mb-4 self-center") }}
|
||||||
|
|
||||||
{{ button.button(text=_("action.continue")) }}
|
{{ button.button(text=_("action.continue")) }}
|
||||||
</form>
|
</form>
|
||||||
|
Reference in New Issue
Block a user