verify_it 0.4.1.beta → 0.4.2
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 +4 -4
- data/CHANGELOG.md +31 -3
- data/README.md +24 -13
- data/config/routes.rb +1 -1
- data/lib/generators/verify_it/install/install_generator.rb +6 -2
- data/lib/generators/verify_it/install/templates/initializer.rb.erb +7 -4
- data/lib/verify_it/engine.rb +0 -6
- data/lib/verify_it/verifiable.rb +3 -2
- data/lib/verify_it/verifier.rb +1 -1
- data/lib/verify_it/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '0638bdc85958eb337d3239d426d9b68a640d1130614406711dad37c1da11c7a2'
|
|
4
|
+
data.tar.gz: 7c40e0432c8e2627c26cbfac91b32f13358fa13a476cb22bc922d3fa1d5db897
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 159d3ae1264b6095b229c4d5d24a925074c1a49c7be7894b44d1c9a8dfb5f87e840f569f5b54ba9d6b968d3092d34dfe1e9d2d5fb608101d1a730c75f572421d
|
|
7
|
+
data.tar.gz: 46c8621291849844500dfb31753870e7d7de574dbb178c1db318fe64a680cf612110361b162479cb5521047f319d8e609443f5f1f1a7d022a26d5cd0ec8c0fd5
|
data/CHANGELOG.md
CHANGED
|
@@ -1,14 +1,42 @@
|
|
|
1
|
-
## [
|
|
1
|
+
## [0.4.2] - 2026-03-21
|
|
2
2
|
|
|
3
3
|
### Added
|
|
4
4
|
- `on_verify_success` callback now receives `request:` as an optional keyword argument,
|
|
5
5
|
enabling apps to access HTTP context (e.g. set session) at verification time.
|
|
6
|
-
Thread: `VerifyIt.verify_code(request:)` → `Verifier#verify_code` → `handle_verification_success`.
|
|
7
6
|
Existing proc-based callbacks are unaffected (procs ignore unknown keyword args);
|
|
8
7
|
lambda-based callbacks should add `request: nil` to their signature.
|
|
8
|
+
- `Verifiable#verify_{channel}_code` now accepts an optional `request:` keyword,
|
|
9
|
+
forwarding it to `on_verify_success` so the model-level API has parity with the
|
|
10
|
+
engine and the direct `VerifyIt.verify_code` call.
|
|
11
|
+
- `current_record_resolver` and `identifier_resolver` are now listed in the
|
|
12
|
+
Configuration Reference table in the README.
|
|
13
|
+
- Install generator accepts `--engine` flag to mount engine routes and generate
|
|
14
|
+
resolver config. Without the flag, the installer produces a minimal initializer
|
|
15
|
+
with no engine routes or resolver boilerplate.
|
|
9
16
|
|
|
10
17
|
### Changed
|
|
11
|
-
-
|
|
18
|
+
- **Breaking (engine only):** `POST /verify/send` renamed to `POST /verify/request`
|
|
19
|
+
to avoid collision with Ruby's `Object#send`. Update client code that hits this
|
|
20
|
+
endpoint. The `/verify/confirm` endpoint is unchanged.
|
|
21
|
+
- Dropped Ruby 3.1 support; minimum required Ruby is now 3.2 (due to `connection_pool >= 3.0` transitive dependency).
|
|
22
|
+
- RuboCop `TargetRubyVersion` updated from 3.0 to 3.2 to match `required_ruby_version`.
|
|
23
|
+
|
|
24
|
+
### Removed
|
|
25
|
+
- Engine no longer auto-includes `VerifyIt::Verifiable` into all ActiveRecord models.
|
|
26
|
+
Add `include VerifyIt::Verifiable` explicitly in models that need it (as shown in
|
|
27
|
+
the README). This avoids polluting unrelated models with verification methods.
|
|
28
|
+
- Install generator no longer unconditionally mounts the engine. Pass `--engine`
|
|
29
|
+
to opt in.
|
|
30
|
+
|
|
31
|
+
### Fixed
|
|
32
|
+
- Initializer template `delivery_channel` default corrected from `:email` to `:sms`.
|
|
33
|
+
- Unused rescue variable in `Verifier#attempt_delivery` (RuboCop `Lint/UselessAssignment`).
|
|
34
|
+
- README testing example now uses correct engine params (`channel`, `auth_headers`)
|
|
35
|
+
instead of the outdated standalone format.
|
|
36
|
+
- README `on_verify_success` callback signature now includes `request: nil`.
|
|
37
|
+
- Install generator mount path changed from `/verify_it` to `/verify` to match
|
|
38
|
+
README examples.
|
|
39
|
+
- Initializer template `on_verify_success` callback signature now includes `request: nil`.
|
|
12
40
|
|
|
13
41
|
## [0.4.0] - 2026-03-07
|
|
14
42
|
|
data/README.md
CHANGED
|
@@ -35,15 +35,21 @@ bundle install
|
|
|
35
35
|
### 1. Generate configuration files
|
|
36
36
|
|
|
37
37
|
```bash
|
|
38
|
-
|
|
38
|
+
rails generate verify_it:install --storage=redis
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
The installer
|
|
41
|
+
The installer generates:
|
|
42
42
|
|
|
43
43
|
- `config/initializers/verify_it.rb` — your main configuration
|
|
44
|
-
- A database migration (if you chose
|
|
44
|
+
- A database migration (if you chose `--storage=database`)
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
Pass `--engine` to also mount the engine routes and generate resolver config:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
rails generate verify_it:install --storage=redis --engine
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
If you chose database storage, run:
|
|
47
53
|
|
|
48
54
|
```bash
|
|
49
55
|
rails db:migrate
|
|
@@ -187,8 +193,10 @@ VerifyIt.cleanup(to: "+15551234567", record: current_user)
|
|
|
187
193
|
|
|
188
194
|
## Rails Engine (HTTP Endpoints)
|
|
189
195
|
|
|
190
|
-
VerifyIt ships a mountable Rails Engine that exposes two JSON endpoints.
|
|
191
|
-
|
|
196
|
+
VerifyIt ships a mountable Rails Engine that exposes two JSON endpoints. Use the
|
|
197
|
+
engine when you want drop-in endpoints without writing controller code. This is
|
|
198
|
+
optional - skip this section if you prefer to handle verification in your own
|
|
199
|
+
controllers using the `Verifiable` concern or the plain Ruby API.
|
|
192
200
|
|
|
193
201
|
### Mount the engine
|
|
194
202
|
|
|
@@ -201,7 +209,7 @@ This adds two routes:
|
|
|
201
209
|
|
|
202
210
|
| Method | Path | Action |
|
|
203
211
|
|---|---|---|
|
|
204
|
-
| POST | `/verify/
|
|
212
|
+
| POST | `/verify/request` | Send a verification code |
|
|
205
213
|
| POST | `/verify/confirm` | Confirm a verification code |
|
|
206
214
|
|
|
207
215
|
### Configure the resolvers
|
|
@@ -240,7 +248,7 @@ end
|
|
|
240
248
|
**Send a code:**
|
|
241
249
|
|
|
242
250
|
```bash
|
|
243
|
-
POST /verify/
|
|
251
|
+
POST /verify/request
|
|
244
252
|
Content-Type: application/json
|
|
245
253
|
|
|
246
254
|
{ "channel": "sms" }
|
|
@@ -297,11 +305,14 @@ en:
|
|
|
297
305
|
| `max_verification_attempts` | `5` | Integer |
|
|
298
306
|
| `max_identifier_changes` | `5` | Integer |
|
|
299
307
|
| `rate_limit_window` | `3600` | Seconds (integer) |
|
|
308
|
+
| `delivery_channel` | `:sms` | `:sms`, `:email` |
|
|
300
309
|
| `sms_sender` | `nil` | Lambda `(to:, code:, context:) { }` |
|
|
301
310
|
| `email_sender` | `nil` | Lambda `(to:, code:, context:) { }` |
|
|
302
311
|
| `on_send` | `nil` | Lambda `(record:, identifier:, channel:) { }` |
|
|
303
|
-
| `on_verify_success` | `nil` | Lambda `(record:, identifier:) { }` |
|
|
312
|
+
| `on_verify_success` | `nil` | Lambda `(record:, identifier:, request: nil) { }` |
|
|
304
313
|
| `on_verify_failure` | `nil` | Lambda `(record:, identifier:, attempts:) { }` |
|
|
314
|
+
| `current_record_resolver` | `nil` | Lambda `(request) { }` — required when mounting the engine |
|
|
315
|
+
| `identifier_resolver` | `nil` | Lambda `(record, channel) { }` — required when mounting the engine |
|
|
305
316
|
| `namespace` | `nil` | Lambda `(record) { }` returning a string or nil |
|
|
306
317
|
| `test_mode` | `false` | Boolean — exposes `result.code` |
|
|
307
318
|
| `bypass_delivery` | `false` | Boolean — skips actual delivery |
|
|
@@ -313,7 +324,7 @@ config.on_send = ->(record:, identifier:, channel:) {
|
|
|
313
324
|
Analytics.track("verification_sent", user_id: record.id, channel: channel)
|
|
314
325
|
}
|
|
315
326
|
|
|
316
|
-
config.on_verify_success = ->(record:, identifier:) {
|
|
327
|
+
config.on_verify_success = ->(record:, identifier:, request: nil) {
|
|
317
328
|
Analytics.track("verification_success", user_id: record.id)
|
|
318
329
|
}
|
|
319
330
|
|
|
@@ -368,14 +379,14 @@ RSpec.configure do |config|
|
|
|
368
379
|
end
|
|
369
380
|
```
|
|
370
381
|
|
|
371
|
-
In a request spec:
|
|
382
|
+
In a request spec (with the engine mounted):
|
|
372
383
|
|
|
373
384
|
```ruby
|
|
374
385
|
it "verifies phone number" do
|
|
375
|
-
post "/verify/
|
|
386
|
+
post "/verify/request", params: { channel: "sms" }, headers: auth_headers
|
|
376
387
|
code = JSON.parse(response.body)["code"] # available in test_mode
|
|
377
388
|
|
|
378
|
-
post "/verify/confirm", params: {
|
|
389
|
+
post "/verify/confirm", params: { channel: "sms", code: code }, headers: auth_headers
|
|
379
390
|
expect(response).to have_http_status(:ok)
|
|
380
391
|
end
|
|
381
392
|
```
|
data/config/routes.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
VerifyIt::Engine.routes.draw do
|
|
4
|
-
post "
|
|
4
|
+
post "request", to: "verifications#create", as: :request_verification
|
|
5
5
|
post "confirm", to: "verifications#verify", as: :confirm_verification
|
|
6
6
|
end
|
|
@@ -10,11 +10,13 @@ module VerifyIt
|
|
|
10
10
|
|
|
11
11
|
source_root File.expand_path("templates", __dir__)
|
|
12
12
|
|
|
13
|
-
desc "Creates a VerifyIt initializer
|
|
13
|
+
desc "Creates a VerifyIt initializer and optionally mounts the engine routes " \
|
|
14
14
|
"and generates a migration when using database storage."
|
|
15
15
|
|
|
16
16
|
class_option :storage, type: :string, default: "memory",
|
|
17
17
|
desc: "Storage backend to use: memory, redis, or database"
|
|
18
|
+
class_option :engine, type: :boolean, default: false,
|
|
19
|
+
desc: "Mount the VerifyIt engine and generate resolver config"
|
|
18
20
|
|
|
19
21
|
def self.next_migration_number(dirname)
|
|
20
22
|
next_num = current_migration_number(dirname) + 1
|
|
@@ -26,7 +28,9 @@ module VerifyIt
|
|
|
26
28
|
end
|
|
27
29
|
|
|
28
30
|
def mount_engine
|
|
29
|
-
|
|
31
|
+
return unless options[:engine]
|
|
32
|
+
|
|
33
|
+
route 'mount VerifyIt::Engine, at: "/verify"'
|
|
30
34
|
end
|
|
31
35
|
|
|
32
36
|
def generate_migration
|
|
@@ -23,24 +23,27 @@ VerifyIt.configure do |config|
|
|
|
23
23
|
# e.g. Twilio, Vonage, etc.
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
<% if options[:engine] -%>
|
|
27
|
+
# Required when mounting the engine (VerifyIt::Engine):
|
|
28
|
+
# Resolve the current authenticated record from a request.
|
|
27
29
|
config.current_record_resolver = ->(request) {
|
|
28
30
|
# User.find_by(id: request.session[:user_id])
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
#
|
|
33
|
+
# Resolve the delivery identifier (phone/email) from the record and channel.
|
|
32
34
|
config.identifier_resolver = ->(record, channel) {
|
|
33
35
|
# channel == :sms ? record.phone_number : record.email
|
|
34
36
|
}
|
|
35
37
|
|
|
38
|
+
<% end -%>
|
|
36
39
|
# Optional overrides (shown with defaults):
|
|
37
40
|
# config.code_length = 6
|
|
38
41
|
# config.code_ttl = 300
|
|
39
42
|
# config.code_format = :numeric
|
|
40
43
|
# config.max_send_attempts = 3
|
|
41
44
|
# config.max_verification_attempts = 5
|
|
42
|
-
# config.delivery_channel = :
|
|
45
|
+
# config.delivery_channel = :sms
|
|
43
46
|
# config.on_send = ->(record:, identifier:, channel:) {}
|
|
44
|
-
# config.on_verify_success = ->(record:, identifier:) {}
|
|
47
|
+
# config.on_verify_success = ->(record:, identifier:, request: nil) {}
|
|
45
48
|
# config.on_verify_failure = ->(record:, identifier:, attempts:) {}
|
|
46
49
|
end
|
data/lib/verify_it/engine.rb
CHANGED
|
@@ -9,11 +9,5 @@ module VerifyIt
|
|
|
9
9
|
initializer "verify_it.i18n" do
|
|
10
10
|
config.i18n.load_path += Dir[Engine.root.join("config", "locales", "**", "*.yml").to_s]
|
|
11
11
|
end
|
|
12
|
-
|
|
13
|
-
initializer "verify_it.active_record" do
|
|
14
|
-
ActiveSupport.on_load(:active_record) do
|
|
15
|
-
include VerifyIt::Verifiable
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
12
|
end
|
|
19
13
|
end
|
data/lib/verify_it/verifiable.rb
CHANGED
|
@@ -30,12 +30,13 @@ module VerifyIt
|
|
|
30
30
|
)
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
define_method(verify_method) do |code|
|
|
33
|
+
define_method(verify_method) do |code, request: nil|
|
|
34
34
|
identifier = send(attribute)
|
|
35
35
|
VerifyIt.verify_code(
|
|
36
36
|
to: identifier,
|
|
37
37
|
code: code,
|
|
38
|
-
record: self
|
|
38
|
+
record: self,
|
|
39
|
+
request: request
|
|
39
40
|
)
|
|
40
41
|
end
|
|
41
42
|
|
data/lib/verify_it/verifier.rb
CHANGED
data/lib/verify_it/version.rb
CHANGED