DarkGhostHunter/Captchavel

How to support multiple types on a single route

Closed this issue · 3 comments

Hi, thanks for the bundle. Also a fan of your medium posts.

If I want to support an API endpoint with more than 1 type of captcha, say v2 checkbox and v2 android, it seems that I need to have 2 different routes so I can apply only a single middleware. Is there another strategy available (short of parsing User-Agent headers) to be able to support multiple types of captchas on a single endpoint? It would be neat to vary on the $input but since that value is in a constant, it is very difficult to support a v2-checkbox-response and v2-android-response field in the different middlewares

Thanks, glad you like my Medium posts. There are more on the way.

About your enquiry, check this sick line.

Yes, you can add the name of the input on a route. In other words, you should be able to point your android app and your frontend to use the same input name (like shared_response_data). Is that what you're looking for?

ah ok, so I can declare middleware like this

Route::post(...)
->withMiddleware('recaptcha:checkbox,my-recaptcha-field-name')

This is a neat trick, but I don't think this solves what I hope to solve.

What I would like to to be able to specify a field name for a captcha service, maybe a map. I have had to split an endpoint like this:

Route::post('api/create-something', [Controller::class, 'store'])
    ->name('my-thing.store')
    ->middleware(['recaptcha:checkbox']);
Route::post('api/create-something/android', [Controller::class, 'store'])
    ->name('my-thing.store.android')
    ->middleware(['recaptcha:android']);

It would be neat if I could specify a map for field mapping to recaptcha service,

$map = [
  'g-recaptcha-response' => 'v2checkbox',
  'g-recaptcha-response-android' => 'v2android',
];

This way I could use 1 endpoint, android sends g-recaptcha-response-android, and others send g-recaptcha-response

g-recaptcha-response-android

I always thought it used the same response input name.

In any case, the middleware only works for one reCAPTCHA type. A major rework should be done to support multiple checks in one route, let alone saying checking the other reCAPTCHA order.

It's far too easy to just use your strategy instead.

Sorry but I can't work on this.