recaptcha 5.14.0 → 5.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3e8441f1c05e97da5513f6b1b42ab0ee020d50b2d06196e4f83100251157c7b
4
- data.tar.gz: c911c40cfe25f413bf9d7ae6a10cce7170856fc45975b455872397c8827db3f6
3
+ metadata.gz: 66a204367215f4ea083958e3f322fc7f2955e7481c09a5cadb1f57cf3acd187e
4
+ data.tar.gz: b6e7c0417b4d81bd0e7f15f7837968fbf65096e5d4a6286e297f1bbc030b7744
5
5
  SHA512:
6
- metadata.gz: bbf6a050959ee4b95693bc336a4ce6f1bad590aefd62ec6f2a3e70f65affc22a44b04902cee5e695a7ea4922b0558e1a63c36b6a430f16094cba416f1d1a7e9f
7
- data.tar.gz: 928673a8221ffe3bcce8d577dce30a405f3b1bdad4cdfc80c15f64044390149134ce4b8d48e8ce18cc28b42c4945dba2641b0982fef009d22e64e79fb117cd66
6
+ metadata.gz: 2c9162ae165cfb00d6ed03f91ef832e90e6bc357cfc31ee71a1a52311910fb183eb40a50967fa04f729243924c1fc9defad7d2030353ccc895b31e7bdb28e210
7
+ data.tar.gz: 8da70c71cb13ce29d7ddfa956795dc2bdcff53ea8aeaa64ad6495e5b4cfa40d82bfd90d9870220173a955e095346ba8f6e451364278af5887e4360b6d5601e07
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## Next
2
2
 
3
+ ## 5.16.0
4
+ * Allow usage of `options[:turbo]` as well as `options[:turbolinks]` for `recaptcha_v3`
5
+
6
+ ## 5.15.0
7
+ * Add 3.2 to the list of Ruby CI versions
8
+ * Add ability to submit verify_recaptcha via POST with JSON Body with `options[:json] = true`
9
+
3
10
  ## 5.14.0
4
11
  * drop json dependency
5
12
 
data/README.md CHANGED
@@ -181,6 +181,7 @@ Some of the options available:
181
181
  | `:response` | Custom response parameter. (default: `params['g-recaptcha-response-data']`)
182
182
  | `:hostname` | Expected hostname or a callable that validates the hostname, see [domain validation](https://developers.google.com/recaptcha/docs/domain_validation) and [hostname](https://developers.google.com/recaptcha/docs/verify#api-response) docs. (default: `nil`, but can be changed by setting `config.hostname`)
183
183
  | `:env` | Current environment. The request to verify will be skipped if the environment is specified in configuration under `skip_verify_env`
184
+ | `:json` | Boolean; defaults to false; if true, will submit the verification request by POST with the request data in JSON
184
185
 
185
186
 
186
187
  ### `invisible_recaptcha_tags`
@@ -418,7 +419,7 @@ but only accepts the following options:
418
419
  | Option | Description |
419
420
  |---------------------|-------------|
420
421
  | `:site_key` | Override site API key |
421
- | `:action` | The name of the [reCAPTCHA action](https://developers.google.com/recaptcha/docs/v3#actions). Actions may only contain alphanumeric characters and slashes, and must not be user-specific. |
422
+ | `:action` | The name of the [reCAPTCHA action](https://developers.google.com/recaptcha/docs/v3#actions). Actions are not case-sensitive and may only contain alphanumeric characters, slashes, and underscores, and must not be user-specific. |
422
423
  | `:nonce` | Optional. Sets nonce attribute for script. Can be generated via `SecureRandom.base64(32)`. (default: `nil`) |
423
424
  | `:callback` | Name of callback function to call with the token. When `element` is `:input`, this defaults to a function named `setInputWithRecaptchaResponseTokenFor#{sanitize_action(action)}` that sets the value of the hidden input to the token. |
424
425
  | `:id` | Specify a unique `id` attribute for the `<input>` element if using `element: :input`. (default: `"g-recaptcha-response-data-"` + `action`) |
@@ -426,7 +427,8 @@ but only accepts the following options:
426
427
  | `:script` | Same as setting both `:inline_script` and `:external_script`. (default: `true`). |
427
428
  | `:inline_script` | If `true`, adds an inline script tag that calls `grecaptcha.execute` for the given `site_key` and `action` and calls the `callback` with the resulting response token. Pass `false` if you want to handle calling `grecaptcha.execute` yourself. (default: `true`) |
428
429
  | `:element` | The element to render, if any (default: `:input`)<br/>`:input`: Renders a hidden `<input type="hidden">` tag. The value of this will be set to the response token by the default `setInputWithRecaptchaResponseTokenFor{action}` callback.<br/>`false`: Doesn't render any tag. You'll have to add a custom callback that does something with the token. |
429
- | `:turbolinks` | If `true`, calls the js function which executes reCAPTCHA after all the dependencies have been loaded. This cannot be used with the js param `:onload`. This makes reCAPTCHAv3 usable with turbolinks. |
430
+ | `:turbo` | If `true`, calls the js function which executes reCAPTCHA after all the dependencies have been loaded. This cannot be used with the js param `:onload`. This makes reCAPTCHAv3 usable with turbo. |
431
+ | `:turbolinks` | Alias of `:turbo`. Will be deprecated soon. |
430
432
  | `:ignore_no_element` | If `true`, adds null element checker for forms that can be removed from the page by javascript like modals with forms. (default: true) |
431
433
 
432
434
  [JavaScript resource (api.js) parameters](https://developers.google.com/recaptcha/docs/invisible#js_param):
@@ -12,7 +12,7 @@ module Recaptcha
12
12
  action = options.delete(:action) || raise(Recaptcha::RecaptchaError, 'action is required')
13
13
  id = options.delete(:id) || "g-recaptcha-response-data-#{dasherize_action(action)}"
14
14
  name = options.delete(:name) || "g-recaptcha-response-data[#{action}]"
15
- turbolinks = options.delete(:turbolinks)
15
+ turbo = options.delete(:turbo) || options.delete(:turbolinks)
16
16
  options[:render] = site_key
17
17
  options[:script_async] ||= false
18
18
  options[:script_defer] ||= false
@@ -24,11 +24,11 @@ module Recaptcha
24
24
  end
25
25
  options[:class] = "g-recaptcha-response #{options[:class]}"
26
26
 
27
- if turbolinks
27
+ if turbo
28
28
  options[:onload] = recaptcha_v3_execute_function_name(action)
29
29
  end
30
30
  html, tag_attributes = components(options)
31
- if turbolinks
31
+ if turbo
32
32
  html << recaptcha_v3_onload_script(site_key, action, callback, id, options)
33
33
  elsif recaptcha_v3_inline_script?(options)
34
34
  html << recaptcha_v3_inline_script(site_key, action, callback, id, options)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Recaptcha
4
- VERSION = '5.14.0'
4
+ VERSION = '5.16.0'
5
5
  end
data/lib/recaptcha.rb CHANGED
@@ -98,7 +98,7 @@ module Recaptcha
98
98
  verify_hash = { 'secret' => secret_key, 'response' => response }
99
99
  verify_hash['remoteip'] = options[:remote_ip] if options.key?(:remote_ip)
100
100
 
101
- reply = api_verification_free(verify_hash, timeout: options[:timeout])
101
+ reply = api_verification_free(verify_hash, timeout: options[:timeout], json: options[:json])
102
102
  success = reply['success'].to_s == 'true' &&
103
103
  hostname_valid?(reply['hostname'], options[:hostname]) &&
104
104
  action_valid?(reply['action'], options[:action]) &&
@@ -152,11 +152,18 @@ module Recaptcha
152
152
  instance
153
153
  end
154
154
 
155
- def self.api_verification_free(verify_hash, timeout: nil)
156
- query = URI.encode_www_form(verify_hash)
157
- uri = URI.parse("#{configuration.verify_url}?#{query}")
155
+ def self.api_verification_free(verify_hash, timeout: nil, json: false)
156
+ if json
157
+ uri = URI.parse(configuration.verify_url)
158
+ request = Net::HTTP::Post.new(uri.request_uri)
159
+ request['Content-Type'] = 'application/json; charset=utf-8'
160
+ request.body = JSON.generate(verify_hash)
161
+ else
162
+ query = URI.encode_www_form(verify_hash)
163
+ uri = URI.parse("#{configuration.verify_url}?#{query}")
164
+ request = Net::HTTP::Get.new(uri.request_uri)
165
+ end
158
166
  http_instance = http_client_for(uri: uri, timeout: timeout)
159
- request = Net::HTTP::Get.new(uri.request_uri)
160
167
  JSON.parse(http_instance.request(request).body)
161
168
  end
162
169
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recaptcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.14.0
4
+ version: 5.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason L Perry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-19 00:00:00.000000000 Z
11
+ date: 2023-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mocha