veri 2.0.0 → 2.0.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 +12 -0
- data/README.md +34 -9
- data/lib/veri/configuration.rb +2 -3
- data/lib/veri/controllers/concerns/authentication.rb +5 -6
- data/lib/veri/inputs/hashing_algorithm.rb +1 -4
- data/lib/veri/models/session.rb +14 -1
- data/lib/veri/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c9b0db1fbb87c0a3b25d47f2142cab1b9143a0ba7751a05c1676ca6e3b4b6ee3
|
|
4
|
+
data.tar.gz: 600d600760a3c0af2fddfece43322193be1ae4255eae0dd1c22d4099a083cb7b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: aaf5ec5aced9ddec1c42367df39be9e4322d3b1b3946bb473bfaee3f668d6fea55d78b48f3f1f0fa1acb8ee4588de8039d054730d3b913ab8036def74054d858
|
|
7
|
+
data.tar.gz: b188516f09afc341584f4460d5caa0e552c94e54dfe3a4bc3fe7a4cddb592acbb8c4957092e4763e88bd1be34ebc122934b40876bd2fc23e87d3b207b5fb2479
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -31,6 +31,7 @@ Consider a multi-tenant SaaS application where users need to manage their active
|
|
|
31
31
|
- [Getting Help and Contributing](#getting-help-and-contributing)
|
|
32
32
|
- [License](#license)
|
|
33
33
|
- [Code of Conduct](#code-of-conduct)
|
|
34
|
+
- [Old Versions](#old-versions)
|
|
34
35
|
|
|
35
36
|
## Installation
|
|
36
37
|
|
|
@@ -69,10 +70,14 @@ Configure Veri in an initializer if customization is needed:
|
|
|
69
70
|
```rb
|
|
70
71
|
# These are the default values; you can change them as needed
|
|
71
72
|
Veri.configure do |config|
|
|
72
|
-
|
|
73
|
-
config.
|
|
74
|
-
|
|
75
|
-
config.
|
|
73
|
+
# Password hashing algorithm (:argon2, :bcrypt, :pbkdf2, or :scrypt)
|
|
74
|
+
config.hashing_algorithm = :argon2
|
|
75
|
+
# Session inactivity timeout (nil means sessions never expire due to inactivity)
|
|
76
|
+
config.inactive_session_lifetime = nil
|
|
77
|
+
# Maximum session duration regardless of activity
|
|
78
|
+
config.total_session_lifetime = 14.days
|
|
79
|
+
# Your user model name
|
|
80
|
+
config.user_model_name = "User"
|
|
76
81
|
end
|
|
77
82
|
```
|
|
78
83
|
|
|
@@ -87,6 +92,12 @@ user.update_password("password")
|
|
|
87
92
|
# Verify a password
|
|
88
93
|
user.verify_password("password")
|
|
89
94
|
```
|
|
95
|
+
Changing a password does not automatically terminate existing sessions. If you want to invalidate the user's sessions after a password change, do so explicitly:
|
|
96
|
+
|
|
97
|
+
```rb
|
|
98
|
+
user.update_password(new_password)
|
|
99
|
+
user.sessions.terminate_all
|
|
100
|
+
```
|
|
90
101
|
|
|
91
102
|
## Controller Integration
|
|
92
103
|
|
|
@@ -98,11 +109,13 @@ Include the authentication module in your controllers and configure protection:
|
|
|
98
109
|
class ApplicationController < ActionController::Base
|
|
99
110
|
include Veri::Authentication
|
|
100
111
|
|
|
101
|
-
|
|
112
|
+
# Require authentication by default
|
|
113
|
+
with_authentication
|
|
102
114
|
end
|
|
103
115
|
|
|
104
116
|
class PicturesController < ApplicationController
|
|
105
|
-
|
|
117
|
+
# Allow public access to index and show actions
|
|
118
|
+
skip_authentication only: [:index, :show]
|
|
106
119
|
end
|
|
107
120
|
```
|
|
108
121
|
|
|
@@ -160,7 +173,7 @@ current_user
|
|
|
160
173
|
# Returns true if user is authenticated
|
|
161
174
|
logged_in?
|
|
162
175
|
|
|
163
|
-
# Authenticates user
|
|
176
|
+
# Authenticates user, returns true on success or false if account is locked
|
|
164
177
|
log_in(user)
|
|
165
178
|
|
|
166
179
|
# Terminates current session
|
|
@@ -407,6 +420,12 @@ To clean up orphaned sessions, use:
|
|
|
407
420
|
Veri::Session.prune
|
|
408
421
|
```
|
|
409
422
|
|
|
423
|
+
Or, for a specific user:
|
|
424
|
+
|
|
425
|
+
```rb
|
|
426
|
+
user.sessions.prune
|
|
427
|
+
```
|
|
428
|
+
|
|
410
429
|
### Tenant Migrations
|
|
411
430
|
|
|
412
431
|
When you rename or remove models used as tenants, you need to update Veri's stored data accordingly. Use these irreversible data migrations:
|
|
@@ -483,7 +502,7 @@ end
|
|
|
483
502
|
## Getting Help and Contributing
|
|
484
503
|
|
|
485
504
|
### Getting Help
|
|
486
|
-
Have a question or need assistance? Open a discussion in
|
|
505
|
+
Have a question or need assistance? Open a discussion in the [discussions section](https://github.com/enjaku4/veri/discussions) for:
|
|
487
506
|
- Usage questions
|
|
488
507
|
- Implementation guidance
|
|
489
508
|
- Feature suggestions
|
|
@@ -498,7 +517,7 @@ Found a bug? Please [create an issue](https://github.com/enjaku4/veri/issues) wi
|
|
|
498
517
|
Ready to contribute? You can:
|
|
499
518
|
- Fix bugs by submitting pull requests
|
|
500
519
|
- Improve documentation
|
|
501
|
-
- Add new features (please discuss first in
|
|
520
|
+
- Add new features (please discuss first in the [discussions section](https://github.com/enjaku4/veri/discussions))
|
|
502
521
|
|
|
503
522
|
Before contributing, please read the [contributing guidelines](https://github.com/enjaku4/veri/blob/main/CONTRIBUTING.md)
|
|
504
523
|
|
|
@@ -509,3 +528,9 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
|
509
528
|
## Code of Conduct
|
|
510
529
|
|
|
511
530
|
Everyone interacting in the Veri project is expected to follow the [code of conduct](https://github.com/enjaku4/veri/blob/main/CODE_OF_CONDUCT.md).
|
|
531
|
+
|
|
532
|
+
## Old Versions
|
|
533
|
+
|
|
534
|
+
Only the latest major version is supported. Older versions are obsolete and not maintained, but their READMEs are available here for reference:
|
|
535
|
+
|
|
536
|
+
[v1.x.x](https://github.com/enjaku4/veri/blob/9c188e16a703141b7cd89dd31d5cd49a557f143d/README.md)
|
data/lib/veri/configuration.rb
CHANGED
|
@@ -17,7 +17,6 @@ module Veri
|
|
|
17
17
|
pbkdf2: Veri::Password::Pbkdf2,
|
|
18
18
|
scrypt: Veri::Password::SCrypt
|
|
19
19
|
}.freeze
|
|
20
|
-
private_constant :HASHERS
|
|
21
20
|
|
|
22
21
|
def hashing_algorithm=(value)
|
|
23
22
|
@hashing_algorithm = Veri::Inputs::HashingAlgorithm.new(
|
|
@@ -60,14 +59,14 @@ module Veri
|
|
|
60
59
|
end
|
|
61
60
|
|
|
62
61
|
def hasher
|
|
63
|
-
HASHERS.fetch(hashing_algorithm)
|
|
62
|
+
HASHERS.fetch(hashing_algorithm)
|
|
64
63
|
end
|
|
65
64
|
|
|
66
65
|
def user_model
|
|
67
66
|
Veri::Inputs::Model.new(
|
|
68
67
|
user_model_name,
|
|
69
68
|
error: Veri::ConfigurationError,
|
|
70
|
-
message: "Invalid user model name `#{user_model_name}`,
|
|
69
|
+
message: "Invalid user model name `#{user_model_name}`, model does not exist"
|
|
71
70
|
).process
|
|
72
71
|
end
|
|
73
72
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require "
|
|
1
|
+
require "zlib"
|
|
2
2
|
|
|
3
3
|
module Veri
|
|
4
4
|
module Authentication
|
|
@@ -25,14 +25,13 @@ module Veri
|
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
def current_user
|
|
28
|
-
|
|
29
|
-
primary_key = user_model.primary_key
|
|
30
|
-
@current_user ||= current_session ? user_model.find_by(primary_key => current_session.authenticatable_id) : nil
|
|
28
|
+
@current_user ||= current_session&.authenticatable
|
|
31
29
|
end
|
|
32
30
|
|
|
33
31
|
def current_session
|
|
34
32
|
token = cookies.encrypted["#{auth_cookie_prefix}_token"]
|
|
35
|
-
|
|
33
|
+
|
|
34
|
+
@current_session ||= Session.lookup(token, resolved_tenant)
|
|
36
35
|
end
|
|
37
36
|
|
|
38
37
|
def log_in(authenticatable)
|
|
@@ -102,7 +101,7 @@ module Veri
|
|
|
102
101
|
end
|
|
103
102
|
|
|
104
103
|
def auth_cookie_prefix
|
|
105
|
-
@auth_cookie_prefix ||= "auth_#{
|
|
104
|
+
@auth_cookie_prefix ||= "auth_#{Zlib.crc32(Marshal.dump(resolved_tenant))}"
|
|
106
105
|
end
|
|
107
106
|
end
|
|
108
107
|
end
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
module Veri
|
|
2
2
|
module Inputs
|
|
3
3
|
class HashingAlgorithm < Veri::Inputs::Base
|
|
4
|
-
HASHING_ALGORITHMS = [:argon2, :bcrypt, :pbkdf2, :scrypt].freeze
|
|
5
|
-
private_constant :HASHING_ALGORITHMS
|
|
6
|
-
|
|
7
4
|
private
|
|
8
5
|
|
|
9
|
-
def processor = -> {
|
|
6
|
+
def processor = -> { Veri::Configuration::HASHERS.key?(@value) ? @value : raise_error }
|
|
10
7
|
end
|
|
11
8
|
end
|
|
12
9
|
end
|
data/lib/veri/models/session.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require "digest"
|
|
1
2
|
require "user_agent_parser"
|
|
2
3
|
|
|
3
4
|
module Veri
|
|
@@ -106,7 +107,7 @@ module Veri
|
|
|
106
107
|
expires_at = Time.current + Veri::Configuration.total_session_lifetime
|
|
107
108
|
|
|
108
109
|
new(
|
|
109
|
-
hashed_token:
|
|
110
|
+
hashed_token: digest_token(token),
|
|
110
111
|
expires_at:,
|
|
111
112
|
authenticatable: user,
|
|
112
113
|
**resolved_tenant
|
|
@@ -126,6 +127,18 @@ module Veri
|
|
|
126
127
|
end
|
|
127
128
|
|
|
128
129
|
alias terminate_all delete_all
|
|
130
|
+
|
|
131
|
+
def lookup(token, resolved_tenant)
|
|
132
|
+
return nil if token.blank?
|
|
133
|
+
|
|
134
|
+
find_by(hashed_token: digest_token(token), **resolved_tenant)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
private
|
|
138
|
+
|
|
139
|
+
def digest_token(token)
|
|
140
|
+
Digest::SHA256.hexdigest(token)
|
|
141
|
+
end
|
|
129
142
|
end
|
|
130
143
|
|
|
131
144
|
private
|
data/lib/veri/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: veri
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.
|
|
4
|
+
version: 2.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- enjaku4
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 2026-03-28 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: argon2
|
|
@@ -147,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
147
147
|
- !ruby/object:Gem::Version
|
|
148
148
|
version: '0'
|
|
149
149
|
requirements: []
|
|
150
|
-
rubygems_version: 4.0.
|
|
150
|
+
rubygems_version: 4.0.3
|
|
151
151
|
specification_version: 4
|
|
152
152
|
summary: Minimal cookie-based authentication library for Ruby on Rails
|
|
153
153
|
test_files: []
|