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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6bd0d2ab55db163c3fe4c23ffde6b23cd161d97c28c3fba95be4f7f88afbd2ea
4
- data.tar.gz: b1afab87840a02696726deb462bff8e53c881e27ac78adf2787ba97cc59ae7ab
3
+ metadata.gz: c9b0db1fbb87c0a3b25d47f2142cab1b9143a0ba7751a05c1676ca6e3b4b6ee3
4
+ data.tar.gz: 600d600760a3c0af2fddfece43322193be1ae4255eae0dd1c22d4099a083cb7b
5
5
  SHA512:
6
- metadata.gz: 99b2f7cc063ebffc0fd94b96fcade3ea4d9e911f21a854146b1b09500319a693dc12d44e4bcb8d64a1382d10d33c8bae4df5321bb22fcc074f0afc9c9ca0f6bd
7
- data.tar.gz: 2d4cc974fb4dacee177d526099d8524cd24b1b8733115a277b1b172fb84bf3e32b42a56558b57ab4552139f6c5364351708304d806cd6eb4eca22aa5497339c5
6
+ metadata.gz: aaf5ec5aced9ddec1c42367df39be9e4322d3b1b3946bb473bfaee3f668d6fea55d78b48f3f1f0fa1acb8ee4588de8039d054730d3b913ab8036def74054d858
7
+ data.tar.gz: b188516f09afc341584f4460d5caa0e552c94e54dfe3a4bc3fe7a4cddb592acbb8c4957092e4763e88bd1be34ebc122934b40876bd2fc23e87d3b207b5fb2479
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## v2.0.2
2
+
3
+ ### Misc
4
+
5
+ - Clarified error message for non-existent user model
6
+
7
+ ## v2.0.1
8
+
9
+ ### Misc
10
+
11
+ - Minor performance improvements and internal refactoring
12
+
1
13
  ## v2.0.0
2
14
 
3
15
  ### Breaking
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
- config.hashing_algorithm = :argon2 # Password hashing algorithm (:argon2, :bcrypt, :pbkdf2, or :scrypt)
73
- config.inactive_session_lifetime = nil # Session inactivity timeout (nil means sessions never expire due to inactivity)
74
- config.total_session_lifetime = 14.days # Maximum session duration regardless of activity
75
- config.user_model_name = "User" # Your user model name
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
- with_authentication # Require authentication by default
112
+ # Require authentication by default
113
+ with_authentication
102
114
  end
103
115
 
104
116
  class PicturesController < ApplicationController
105
- skip_authentication only: [:index, :show] # Allow public access to index and show actions
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 and creates session, returns true on success or false if account is locked
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 our [discussions section](https://github.com/enjaku4/veri/discussions) for:
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 our [discussions section](https://github.com/enjaku4/veri/discussions))
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)
@@ -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) { raise Veri::Error, "Invalid hashing algorithm: #{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}`, expected an ActiveRecord model name as a string"
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 "digest/sha2"
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
- user_model = Veri::Configuration.user_model
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
- @current_session ||= token ? Session.find_by(hashed_token: Digest::SHA256.hexdigest(token), **resolved_tenant) : nil
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_#{Digest::SHA2.hexdigest(Marshal.dump(resolved_tenant))[0..7]}"
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 = -> { HASHING_ALGORITHMS.include?(@value) ? @value : raise_error }
6
+ def processor = -> { Veri::Configuration::HASHERS.key?(@value) ? @value : raise_error }
10
7
  end
11
8
  end
12
9
  end
@@ -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: Digest::SHA256.hexdigest(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
@@ -1,3 +1,3 @@
1
1
  module Veri
2
- VERSION = "2.0.0".freeze
2
+ VERSION = "2.0.2".freeze
3
3
  end
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.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: 1980-01-02 00:00:00.000000000 Z
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.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: []