veri 1.0.0 → 1.1.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 +4 -4
- data/CHANGELOG.md +16 -0
- data/README.md +28 -21
- data/lib/veri/models/session.rb +1 -0
- data/lib/veri/railtie.rb +5 -1
- data/lib/veri/version.rb +1 -1
- data/veri.gemspec +5 -1
- metadata +11 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5059569cdd9359f72eb4852779102dca282a75176073020888ecfffb6ac716c0
|
|
4
|
+
data.tar.gz: ee0b24a4e5a9f105f10c6cb7cb550f90449a87031622577cc89211edac5bb06d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '0910cd4e2a58796521a755ed2e6414d647270ce94582c2247574f2189e2949d5cb9297f0cbda06414586f845bb00a484974a2752e079de7906c770cd153afd20'
|
|
7
|
+
data.tar.gz: 6bf989a229323abf6160b91bded464993f8606810d5883a40d32eb7e6e66c0bb4742cae90cf5246b1848f2b20a9014d66cf0867dea20de1dc10dbe297f1e1c5e
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
## v1.1.0
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
- Added `Veri::Session.in_tenant` method to fetch sessions for a specific tenant
|
|
6
|
+
|
|
7
|
+
### Misc
|
|
8
|
+
|
|
9
|
+
- Added support for Rails 8.1
|
|
10
|
+
|
|
11
|
+
## v1.0.1
|
|
12
|
+
|
|
13
|
+
### Bugs
|
|
14
|
+
|
|
15
|
+
- Fixed tenant validation blocking Rails console and database commands when orphaned tenant classes exist
|
|
16
|
+
|
|
1
17
|
## v1.0.0
|
|
2
18
|
|
|
3
19
|
### Breaking
|
data/README.md
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
# Veri: Minimal Authentication
|
|
1
|
+
# Veri: Minimal Authentication for Rails
|
|
2
2
|
|
|
3
3
|
[](http://badge.fury.io/rb/veri)
|
|
4
|
+
[](https://rubygems.org/gems/veri)
|
|
4
5
|
[](https://github.com/enjaku4/veri/actions/workflows/ci.yml)
|
|
6
|
+
[](LICENSE)
|
|
5
7
|
|
|
6
|
-
Veri is a cookie-based authentication library for Ruby on Rails that provides essential
|
|
8
|
+
Veri is a cookie-based authentication library for Ruby on Rails. Unlike other solutions that generate controllers, views, and mailers for you, Veri provides only essential building blocks. It's ideal for applications that require custom authentication experiences: you design your own interfaces and flows, while Veri handles the complex underlying mechanics of secure password storage and session verification. On top of that, Veri supports multi-tenancy, granular session management, multiple password hashing algorithms, and includes a user impersonation feature.
|
|
7
9
|
|
|
8
|
-
**
|
|
10
|
+
**Example of Usage:**
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
- Multiple password hashing algorithms (argon2, bcrypt, pbkdf2, scrypt)
|
|
12
|
-
- Granular session management and control
|
|
13
|
-
- Return path handling
|
|
14
|
-
- User impersonation feature
|
|
15
|
-
- Account lockout functionality
|
|
16
|
-
- Multi-tenancy support
|
|
12
|
+
Consider a multi-tenant SaaS application where users can view all their active sessions across devices and browsers and terminate specific sessions remotely. Administrators have the same interface in their admin panel, giving them visibility into user activity and the ability to end sessions or lock accounts for security. Additionally, administrators can temporarily assume a user’s identity for troubleshooting. All of this is easily handled with Veri.
|
|
17
13
|
|
|
18
14
|
## Table of Contents
|
|
19
15
|
|
|
@@ -65,7 +61,7 @@ rails db:migrate
|
|
|
65
61
|
|
|
66
62
|
## Configuration
|
|
67
63
|
|
|
68
|
-
|
|
64
|
+
Configure Veri in an initializer if customization is needed:
|
|
69
65
|
|
|
70
66
|
```rb
|
|
71
67
|
# These are the default values; you can change them as needed
|
|
@@ -174,7 +170,7 @@ current_session
|
|
|
174
170
|
|
|
175
171
|
### User Impersonation (Shapeshifting)
|
|
176
172
|
|
|
177
|
-
Veri provides user impersonation functionality that allows
|
|
173
|
+
Veri provides user impersonation functionality that allows administrators to temporarily assume another user's identity:
|
|
178
174
|
|
|
179
175
|
```rb
|
|
180
176
|
module Admin
|
|
@@ -217,9 +213,9 @@ Controller helper:
|
|
|
217
213
|
shapeshifter?
|
|
218
214
|
```
|
|
219
215
|
|
|
220
|
-
### When
|
|
216
|
+
### When Unauthenticated
|
|
221
217
|
|
|
222
|
-
Override this private method to customize
|
|
218
|
+
Override this private method to customize behavior for unauthenticated users:
|
|
223
219
|
|
|
224
220
|
```rb
|
|
225
221
|
class ApplicationController < ActionController::Base
|
|
@@ -231,10 +227,8 @@ class ApplicationController < ActionController::Base
|
|
|
231
227
|
|
|
232
228
|
private
|
|
233
229
|
|
|
234
|
-
# Customize unauthenticated user handling
|
|
235
230
|
def when_unauthenticated
|
|
236
|
-
# By default redirects back
|
|
237
|
-
# otherwise responds with 401 Unauthorized
|
|
231
|
+
# By default, redirects back (HTML) or returns 401 (other formats)
|
|
238
232
|
redirect_to login_path
|
|
239
233
|
end
|
|
240
234
|
end
|
|
@@ -313,7 +307,7 @@ user.sessions.prune
|
|
|
313
307
|
|
|
314
308
|
## Account Lockout
|
|
315
309
|
|
|
316
|
-
Veri provides account lockout functionality to temporarily disable user accounts
|
|
310
|
+
Veri provides account lockout functionality to temporarily disable user accounts.
|
|
317
311
|
|
|
318
312
|
```rb
|
|
319
313
|
# Lock a user account
|
|
@@ -332,11 +326,11 @@ User.locked
|
|
|
332
326
|
User.unlocked
|
|
333
327
|
```
|
|
334
328
|
|
|
335
|
-
When an account is locked, the user cannot log in. If
|
|
329
|
+
When an account is locked, the user cannot log in. If they're already logged in, their sessions are terminated and they are treated as unauthenticated.
|
|
336
330
|
|
|
337
331
|
## Multi-Tenancy
|
|
338
332
|
|
|
339
|
-
Veri supports multi-tenancy, allowing you to isolate authentication sessions between different tenants
|
|
333
|
+
Veri supports multi-tenancy, allowing you to isolate authentication sessions between different tenants such as organizations, clients, or subdomains.
|
|
340
334
|
|
|
341
335
|
### Setting Up Multi-Tenancy
|
|
342
336
|
|
|
@@ -369,6 +363,19 @@ Sessions expose their tenant through `tenant` method:
|
|
|
369
363
|
session.tenant
|
|
370
364
|
```
|
|
371
365
|
|
|
366
|
+
To manage sessions for a specific tenant:
|
|
367
|
+
|
|
368
|
+
```rb
|
|
369
|
+
# Fetch all sessions for a given tenant
|
|
370
|
+
Veri::Session.in_tenant(tenant)
|
|
371
|
+
|
|
372
|
+
# Fetch sessions for a specific user within a tenant
|
|
373
|
+
user.sessions.in_tenant(tenant)
|
|
374
|
+
|
|
375
|
+
# Terminate all sessions for a specific user within a tenant
|
|
376
|
+
user.sessions.in_tenant(tenant).terminate_all
|
|
377
|
+
```
|
|
378
|
+
|
|
372
379
|
### Migration Helpers
|
|
373
380
|
|
|
374
381
|
Handle tenant changes when models are renamed or removed. These are irreversible data migrations.
|
|
@@ -400,7 +407,7 @@ Access authentication state in your views:
|
|
|
400
407
|
|
|
401
408
|
## Testing
|
|
402
409
|
|
|
403
|
-
Veri doesn't
|
|
410
|
+
Veri doesn't include test helpers, but you can easily create your own:
|
|
404
411
|
|
|
405
412
|
### Request Specs (Recommended)
|
|
406
413
|
|
data/lib/veri/models/session.rb
CHANGED
|
@@ -8,6 +8,7 @@ module Veri
|
|
|
8
8
|
belongs_to :original_authenticatable, class_name: Veri::Configuration.user_model_name, optional: true
|
|
9
9
|
belongs_to :tenant, polymorphic: true, optional: true
|
|
10
10
|
|
|
11
|
+
scope :in_tenant, -> (tenant) { where(**Veri::Inputs::Tenant.new(tenant).resolve) }
|
|
11
12
|
scope :active, -> { where.not(id: expired.select(:id)).where.not(id: inactive.select(:id)) }
|
|
12
13
|
scope :expired, -> { where(expires_at: ...Time.current) }
|
|
13
14
|
scope :inactive, -> do
|
data/lib/veri/railtie.rb
CHANGED
|
@@ -2,6 +2,10 @@ require "rails/railtie"
|
|
|
2
2
|
|
|
3
3
|
module Veri
|
|
4
4
|
class Railtie < Rails::Railtie
|
|
5
|
+
def self.server_running?
|
|
6
|
+
!!defined?(Rails::Server)
|
|
7
|
+
end
|
|
8
|
+
|
|
5
9
|
def self.table_exists?
|
|
6
10
|
ActiveRecord::Base.connection.data_source_exists?("veri_sessions")
|
|
7
11
|
rescue ActiveRecord::NoDatabaseError, ActiveRecord::ConnectionNotEstablished
|
|
@@ -10,7 +14,7 @@ module Veri
|
|
|
10
14
|
|
|
11
15
|
initializer "veri.to_prepare" do |app|
|
|
12
16
|
app.config.to_prepare do
|
|
13
|
-
if Veri::Railtie.table_exists?
|
|
17
|
+
if Veri::Railtie.server_running? && Veri::Railtie.table_exists?
|
|
14
18
|
Veri::Session.where.not(tenant_id: nil).distinct.pluck(:tenant_type).each do |tenant_class|
|
|
15
19
|
tenant_class.constantize
|
|
16
20
|
rescue NameError => e
|
data/lib/veri/version.rb
CHANGED
data/veri.gemspec
CHANGED
|
@@ -4,12 +4,16 @@ Gem::Specification.new do |spec|
|
|
|
4
4
|
spec.name = "veri"
|
|
5
5
|
spec.version = Veri::VERSION
|
|
6
6
|
spec.authors = ["enjaku4"]
|
|
7
|
+
spec.email = ["enjaku4@icloud.com"]
|
|
7
8
|
spec.homepage = "https://github.com/enjaku4/veri"
|
|
8
9
|
spec.metadata["homepage_uri"] = spec.homepage
|
|
9
10
|
spec.metadata["source_code_uri"] = spec.homepage
|
|
10
11
|
spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md"
|
|
12
|
+
spec.metadata["bug_tracker_uri"] = "#{spec.homepage}/issues"
|
|
13
|
+
spec.metadata["documentation_uri"] = "#{spec.homepage}/blob/main/README.md"
|
|
11
14
|
spec.metadata["rubygems_mfa_required"] = "true"
|
|
12
15
|
spec.summary = "Minimal cookie-based authentication library for Ruby on Rails"
|
|
16
|
+
spec.description = "Veri provides cookie-based authentication for Ruby on Rails applications with secure password storage, granular session management, multi-tenancy support, and user impersonation feature, without imposing business logic"
|
|
13
17
|
spec.license = "MIT"
|
|
14
18
|
spec.required_ruby_version = ">= 3.2", "< 3.5"
|
|
15
19
|
|
|
@@ -23,7 +27,7 @@ Gem::Specification.new do |spec|
|
|
|
23
27
|
spec.add_dependency "bcrypt", "~> 3.0"
|
|
24
28
|
spec.add_dependency "dry-configurable", "~> 1.1"
|
|
25
29
|
spec.add_dependency "dry-types", "~> 1.7"
|
|
26
|
-
spec.add_dependency "rails", ">= 7.2", "< 8.
|
|
30
|
+
spec.add_dependency "rails", ">= 7.2", "< 8.2"
|
|
27
31
|
spec.add_dependency "scrypt", "~> 3.0"
|
|
28
32
|
spec.add_dependency "user_agent_parser", "~> 2.0"
|
|
29
33
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: veri
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- enjaku4
|
|
@@ -74,7 +74,7 @@ dependencies:
|
|
|
74
74
|
version: '7.2'
|
|
75
75
|
- - "<"
|
|
76
76
|
- !ruby/object:Gem::Version
|
|
77
|
-
version: '8.
|
|
77
|
+
version: '8.2'
|
|
78
78
|
type: :runtime
|
|
79
79
|
prerelease: false
|
|
80
80
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -84,7 +84,7 @@ dependencies:
|
|
|
84
84
|
version: '7.2'
|
|
85
85
|
- - "<"
|
|
86
86
|
- !ruby/object:Gem::Version
|
|
87
|
-
version: '8.
|
|
87
|
+
version: '8.2'
|
|
88
88
|
- !ruby/object:Gem::Dependency
|
|
89
89
|
name: scrypt
|
|
90
90
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -113,6 +113,11 @@ dependencies:
|
|
|
113
113
|
- - "~>"
|
|
114
114
|
- !ruby/object:Gem::Version
|
|
115
115
|
version: '2.0'
|
|
116
|
+
description: Veri provides cookie-based authentication for Ruby on Rails applications
|
|
117
|
+
with secure password storage, granular session management, multi-tenancy support,
|
|
118
|
+
and user impersonation feature, without imposing business logic
|
|
119
|
+
email:
|
|
120
|
+
- enjaku4@icloud.com
|
|
116
121
|
executables: []
|
|
117
122
|
extensions: []
|
|
118
123
|
extra_rdoc_files: []
|
|
@@ -149,6 +154,8 @@ metadata:
|
|
|
149
154
|
homepage_uri: https://github.com/enjaku4/veri
|
|
150
155
|
source_code_uri: https://github.com/enjaku4/veri
|
|
151
156
|
changelog_uri: https://github.com/enjaku4/veri/blob/main/CHANGELOG.md
|
|
157
|
+
bug_tracker_uri: https://github.com/enjaku4/veri/issues
|
|
158
|
+
documentation_uri: https://github.com/enjaku4/veri/blob/main/README.md
|
|
152
159
|
rubygems_mfa_required: 'true'
|
|
153
160
|
rdoc_options: []
|
|
154
161
|
require_paths:
|
|
@@ -167,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
167
174
|
- !ruby/object:Gem::Version
|
|
168
175
|
version: '0'
|
|
169
176
|
requirements: []
|
|
170
|
-
rubygems_version: 3.7.
|
|
177
|
+
rubygems_version: 3.7.2
|
|
171
178
|
specification_version: 4
|
|
172
179
|
summary: Minimal cookie-based authentication library for Ruby on Rails
|
|
173
180
|
test_files: []
|