Hello,

I just started to look over the v3 version of recaptcha and noticed there is only this module for D7.
There is an issue for the D8 recaptcha here to add support for v3, but no work has been done yet.
Should we port this module or implement in the D8 version of recaptcha ?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

prics created an issue. See original summary.

dench0’s picture

I'm don't know. If someone does not do it before, then I'm planing to do 8 version at the next month.

FiNeX’s picture

It should be very useful because reCaptha v2 is almost unusable, a lot of spambot are able to solve it :-(

majid.ali’s picture

I have ported this module to D8, can you please make me co maintainer of this module so i can push the code.

breidert’s picture

+1
It would be great to see the ported version of the module in this namespace.

B-Prod’s picture

Maintainers, could it be possible to create a D8 branch, so we could provide patches against it?
A simple empty README file would be enough :-)

@majid.ali already made a port for D8, it would be great that he could provide a patch on such D8 branch, so we can go on.

It would be great to use this existing project, instead of creating a new project apart...

@majid.ali Could you please create an issue for becoming a project maintainer, as stated in the Drupal documentation:
https://www.drupal.org/node/251466#procedure---own-project

majid.ali’s picture

Thanks @b-prod i have created an issue to to be co maintainer as stated in the Drupal documentation. https://www.drupal.org/project/recaptcha_v3/issues/3094424

I would be happy to use this existing namespace rather creating a new one.

B-Prod’s picture

@majid.ali great, I also created such a request: https://www.drupal.org/project/recaptcha_v3/issues/3094620

B-Prod’s picture

And a request to the d.org project ownership queue, hoping they could create the D8 branch do unblock us : https://www.drupal.org/project/projectownership/issues/3094622

B-Prod’s picture

@majid.ali I created the new D8 branch: https://www.drupal.org/project/recaptcha_v3/releases/8.x-1.x-dev

So you can now provide a patch with your code for review here.

You are also now a co-maintainer of this module, so we can go further now.

dench0’s picture

FileSize
13.6 KB

@majid.ali, B-Prod I attached archive with my code for poring this module to d8. I'm not remembering at which phase I stopped, because this code was written like 5-6 month ago. Maybe you would find something useful.

B-Prod’s picture

@dench0 Thank you for the source code!

@majid.ali Should I use the @dench0 code or wait for yours?

  • 660c936 committed on 8.x-1.x
    Issue #3029161 by dench0, B-Prod, prics: integrate and review code from...
B-Prod’s picture

Version: 7.x-1.0-alpha1 » 8.x-1.x-dev
B-Prod’s picture

@dench0 your code has been integrated and adapted, we will perform tests and reviews next week, thanks again for your contribution!

majid.ali’s picture

@drench0 @b-prod I have merged code from my module and created a patch. Its working with latest captcha /8.x-1.0-beta4 and reCaptcha 8.x-2.4 please review it.

  • 9f7ef5e committed on 8.x-1.x
    Issue #3029161 by prics: Port the module to D8
    
dench0’s picture

Here the new patch.
Short list of changes from the last commit:
1. Removed directory "src/Entity/Controller". @majid.ali why you are moved list builder there?
2. Modified and moved Entity interface to the Drupal\recaptcha_v3 namespace
3. Removed methods not related to the entity from ReCaptchaV3Action entity (token verification and creating empty action).
4. Updated ReCaptchaV3Action entity definition (replace route_provider class and remove local_task_provider - previously used classes from contrib module entity).
5. Added function for recaptcha token verification to the recaptcha_v3.module file.

@majid.ali question about this line:

$form_state->setRebuild(TRUE);

in recaptcha_v3_pre_captcha_element_process function.
I'm not understood for which purposes this line added?

majid.ali’s picture

@dench0 According to the documentation https://www.drupal.org/docs/8/api/entity-api/creating-a-content-entity-t... list builder is in "src/Entity/Controller"

$form_state->setRebuild(TRUE); can be removed.

dench0’s picture

@majid.ali
1. In our module we have config entity, not content entity.
2. I'm thinking in that API documentation page confused different things. Exist two classes related to the entity list building: EntityListController and EntityListBuilder. I'm thinking from the names of these two classes you can understand purposes of the each one. Then you can check core module block, which using exactly that 2 classes: first one in the namespace Drupal\block\Controller (not in Drupal\block\Entity\Controller) and second - Drupal\block
3. I never saw before using of that strange namespace: neither in core nor in contributed modules (except captcha).

  • dench0 committed 35465be on 8.x-1.x
    Issue #3029161 by dench0, majid.ali, B-Prod: Port the module to D8
    
majid.ali’s picture

@dench0 I was doing testing and found two issues, first one is more critical.
On line 208 of module file we are setting response in $form_state $form_state->set('recaptcha_v3', $verification_response);
$form_state dose not retain this value after validation function. Therefore on a fallback challenge when you submit the form again it again sets recaptcha_v3 validation

function recaptcha_v3_post_captcha_element_process(&$element, FormStateInterface $form_state, &$complete_form) {
  if ($form_state->getTemporaryValue('recaptcha_v3_action_name') && !$form_state->has('recaptcha_v3')) {
    $element['#captcha_validate'] = 'recaptcha_v3_validate';
  }
  return $element;
}

And fallback challenge fails. I am struggling to find a solution. I am not sure if its right to put the response in session with captcha sid and not to use $form_state for that?

Second issue is if you enable recaptcha module and use it as fallback challenge then we get into trouble of different "google/recaptcha" library version. We are using the latest one and recpatcha has an old one which has a different structure. Should we use the same version of create a patch for recaptcha ?

  • dench0 committed 1996cfe on 8.x-1.x
    Issue #3029161 by dench0, majid.ali, B-Prod: Port the module to D8
    
dench0’s picture

I pushed code with some changes, sorry that I done this without any discussion - I'm thinking in this stage it not big deal, because module does not have even alpha release.

You can check current solution to force form state caching starting from this line https://git.drupalcode.org/project/recaptcha_v3/commit/1996cfe#d011fd961... (line 209). There in comment you can see my concern about it.
Right now I don't know if this solution is bullet proof and will it correct for all cases. Maybe better in this function recaptcha_v3_pre_captcha_element_process on input processing add extra form element with captcha response.

dench0’s picture

So now need to check current form state caching solution.
Also need to write some js code for repeating token request after some time interval (it seems like after 2 minutes captcha response became outdated and token validation failed).

majid.ali’s picture

Status: Active » Fixed
majid.ali’s picture

Status: Fixed » Closed (fixed)