Class: SpreeCmCommissioner::TurnstileTokenValidator
- Inherits:
-
BaseInteractor
- Object
- BaseInteractor
- SpreeCmCommissioner::TurnstileTokenValidator
- Defined in:
- app/interactors/spree_cm_commissioner/turnstile_token_validator.rb
Constant Summary collapse
- SITE_VERIFY_URL =
'https://challenges.cloudflare.com/turnstile/v0/siteverify'.freeze
- CONFIG_ERROR_CODES =
https://developers.cloudflare.com/turnstile/get-started/server-side-validation/#error-codes Our own secret/setup is wrong -- not something a retry or a fresh token can fix.
%w[missing-input-secret invalid-input-secret bad-request].freeze
- EXPIRED_ERROR_CODES =
The token itself expired or was already redeemed -- a fresh token will fix this.
%w[timeout-or-duplicate].freeze
- INVALID_TOKEN_ERROR_CODES =
The token we received was malformed/missing -- client should fetch a new one.
%w[missing-input-response invalid-input-response].freeze
Instance Method Summary collapse
Instance Method Details
#call ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/interactors/spree_cm_commissioner/turnstile_token_validator.rb', line 15 def call context.fail!(message: I18n.t('turnstile.token_missing'), error_code: :token_missing) if token.blank? response = verify_token body = parse_response(response) handle_failure(body) unless body['success'] context.challenge_ts = body['challenge_ts'] context.hostname = body['hostname'] context.action = body['action'] end |