Skip to content

Commit 7ba9873

Browse files
authored
Removed reCAPTCHA from registration (#77)
1 parent 2dd47e7 commit 7ba9873

5 files changed

Lines changed: 7 additions & 100 deletions

File tree

application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<properties>
3-
<version>1.8.0</version>
3+
<version>1.9.0</version>
44
</properties>

keycloakify/src/login/pages/register/Form.tsx

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Button } from "@/components/ui/button";
22
import { useKcClsx } from "@keycloakify/login-ui/useKcClsx";
3-
import { useEffect, useState, type FormEvent } from "react";
3+
import { useState } from "react";
44
import { assert } from "tsafe/assert";
55
import { useKcContext } from "../../KcContext";
66
import { UserProfileFormFields } from "../../components/UserProfileFormFields";
@@ -16,64 +16,12 @@ export function Form() {
1616
const [isFormSubmittable, setIsFormSubmittable] = useState(false);
1717
const [areTermsAccepted, setAreTermsAccepted] = useState(false);
1818

19-
const recaptchaRequired = kcContext.recaptchaRequired;
20-
const recaptchaSiteKey = kcContext.recaptchaSiteKey;
21-
const recaptchaAction = kcContext.recaptchaAction;
22-
23-
// reCAPTCHA v3 is invisible: load the API with the site key on mount, then on
24-
// submit fetch a token for the action and POST it in the `g-recaptcha-response`
25-
// field (the param Keycloak's recaptcha authenticator reads). No widget.
26-
useEffect(() => {
27-
if (!recaptchaRequired || recaptchaSiteKey === undefined) {
28-
return;
29-
}
30-
const src = `https://www.google.com/recaptcha/api.js?render=${recaptchaSiteKey}`;
31-
if (document.querySelector(`script[src="${src}"]`) !== null) {
32-
return;
33-
}
34-
const script = document.createElement("script");
35-
script.src = src;
36-
script.async = true;
37-
document.head.appendChild(script);
38-
}, [recaptchaRequired, recaptchaSiteKey]);
39-
40-
const onSubmit = (event: FormEvent<HTMLFormElement>) => {
41-
if (!recaptchaRequired || recaptchaSiteKey === undefined) {
42-
return; // no captcha -> let the form submit normally
43-
}
44-
event.preventDefault();
45-
const form = event.currentTarget;
46-
const grecaptcha = (window as any).grecaptcha;
47-
if (grecaptcha === undefined) {
48-
form.submit();
49-
return;
50-
}
51-
grecaptcha.ready(() => {
52-
grecaptcha
53-
.execute(recaptchaSiteKey, { action: recaptchaAction ?? "register" })
54-
.then((token: string) => {
55-
let field = form.querySelector<HTMLInputElement>(
56-
'input[name="g-recaptcha-response"]'
57-
);
58-
if (field === null) {
59-
field = document.createElement("input");
60-
field.type = "hidden";
61-
field.name = "g-recaptcha-response";
62-
form.appendChild(field);
63-
}
64-
field.value = token;
65-
form.submit();
66-
});
67-
});
68-
};
69-
7019
return (
7120
<form
7221
id="kc-register-form"
7322
action={kcContext.url.registrationAction}
7423
className="space-y-4"
7524
method="post"
76-
onSubmit={onSubmit}
7725
>
7826
<UserProfileFormFields
7927
onIsFormSubmittableValueChange={setIsFormSubmittable}

keycloakify/src/login/pages/register/Page.stories.tsx

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -176,29 +176,6 @@ export const WithEmailAsUsername: Story = {
176176
}
177177
};
178178

179-
export const WithRecaptcha: Story = {
180-
args: {
181-
kcContext: {
182-
scripts: ["https://www.google.com/recaptcha/api.js?hl=en"],
183-
recaptchaRequired: true,
184-
recaptchaSiteKey: "6LfQHvApAAAAAE73SYTd5vS0lB1Xr7zdiQ-6iBVa"
185-
}
186-
}
187-
};
188-
189-
export const WithRecaptchaFrench: Story = {
190-
args: {
191-
kcContext: {
192-
locale: {
193-
currentLanguageTag: "fr"
194-
},
195-
scripts: ["https://www.google.com/recaptcha/api.js?hl=fr"],
196-
recaptchaRequired: true,
197-
recaptchaSiteKey: "6LfQHvApAAAAAE73SYTd5vS0lB1Xr7zdiQ-6iBVa"
198-
}
199-
}
200-
};
201-
202179
export const WithPasswordMinLength8: Story = {
203180
args: {
204181
kcContext: {

realms/schuly-realm.json

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"referrerPolicy": "no-referrer",
1414
"xRobotsTag": "none",
1515
"xFrameOptions": "SAMEORIGIN",
16-
"contentSecurityPolicy": "frame-src 'self' https://www.google.com https://recaptcha.google.com; frame-ancestors 'self'; object-src 'none';",
16+
"contentSecurityPolicy": "frame-src 'self'; frame-ancestors 'self'; object-src 'none';",
1717
"strictTransportSecurity": "max-age=31536000; includeSubDomains"
1818
},
1919
"smtpServer": {
@@ -389,7 +389,7 @@
389389
},
390390
{
391391
"alias": "registration",
392-
"description": "Registration flow with reCAPTCHA bot protection",
392+
"description": "Registration flow",
393393
"providerId": "basic-flow",
394394
"topLevel": true,
395395
"builtIn": false,
@@ -424,29 +424,11 @@
424424
"requirement": "REQUIRED",
425425
"priority": 50,
426426
"userSetupAllowed": false
427-
},
428-
{
429-
"authenticator": "registration-recaptcha-action",
430-
"authenticatorFlow": false,
431-
"requirement": "REQUIRED",
432-
"priority": 60,
433-
"authenticatorConfig": "recaptcha-config",
434-
"userSetupAllowed": false
435427
}
436428
]
437429
}
438430
],
439-
"authenticatorConfig": [
440-
{
441-
"alias": "recaptcha-config",
442-
"config": {
443-
"site.key": "${env.RECAPTCHA_SITE_KEY}",
444-
"secret": "${env.RECAPTCHA_SECRET}",
445-
"useRecaptchaNet": "false",
446-
"action": "register"
447-
}
448-
}
449-
],
431+
"authenticatorConfig": [],
450432
"requiredActions": [
451433
{
452434
"alias": "CONFIGURE_TOTP",

scripts/resolve-realm-env.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# environment BEFORE Keycloak imports them. Keycloak's realm import does not
44
# substitute environment variables itself (only ${vault.x}, at use-time), so the
55
# committed realm keeps clean ${env.*} placeholders and this script fills them in
6-
# at startup from the values passed to the container (e.g. SMTP creds, reCAPTCHA
7-
# keys). Non-env placeholders like ${username}/${email} are left untouched.
6+
# at startup from the values passed to the container (e.g. SMTP creds).
7+
# Non-env placeholders like ${username}/${email} are left untouched.
88
set -euo pipefail
99

1010
import_dir="/opt/keycloak/data/import"

0 commit comments

Comments
 (0)