quo_vadis 2.2.2 → 2.2.4
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 +10 -0
- data/README.md +38 -0
- data/lib/quo_vadis/constraints/logged_in.rb +13 -0
- data/lib/quo_vadis/constraints/logged_out.rb +13 -0
- data/lib/quo_vadis/controller.rb +9 -0
- data/lib/quo_vadis/version.rb +1 -1
- data/lib/quo_vadis.rb +2 -0
- data/test/integration/controller_test.rb +8 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d059bd573146f59fff8f4fff1ef953c4da0bff83b07125efafadfd40334a9a8
|
4
|
+
data.tar.gz: 744bd5ac56082016453309608721c76e37dcb8827f1c7111102d8a0d06961608
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 746819329e2b544e00ca92ccf75cd5293f58160da3243db0c0d6b9dba6d70fde94e59492fd2d73387e20d5f60487dbb98f56eb8c618573215a6b9efd027b4442
|
7
|
+
data.tar.gz: caf55aa31161fe96980ab58b2a3d477202e03b80fa2a4a684477bfb6f3aef4c4033ff670b03f2d434cbda45ff4bc23291d288b196440f372545c1eaccd89732f
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,16 @@
|
|
4
4
|
## HEAD
|
5
5
|
|
6
6
|
|
7
|
+
## 2.2.4 (25 June 2024)
|
8
|
+
|
9
|
+
* Add logged-{in, out} routing constraints.
|
10
|
+
|
11
|
+
|
12
|
+
## 2.2.3 (22 May 2024)
|
13
|
+
|
14
|
+
* Add login shortcut for speedier tests.
|
15
|
+
|
16
|
+
|
7
17
|
## 2.2.2 (30 April 2024)
|
8
18
|
|
9
19
|
* Do not update last activity time for ActiveStorage (#23).
|
data/README.md
CHANGED
@@ -12,6 +12,7 @@ Simple to integrate into your application. The main task is customising the exa
|
|
12
12
|
### General features
|
13
13
|
|
14
14
|
- Works with any model, e.g. `User` or `Person`.
|
15
|
+
- Works with multiple models, e.g. `User` and `Admin`.
|
15
16
|
- Works with any identifier, e.g. `:username` or `:email`.
|
16
17
|
- Minimal footprint in your models and controllers.
|
17
18
|
- Does not touch your existing database tables.
|
@@ -31,6 +32,10 @@ Simple to integrate into your application. The main task is customising the exa
|
|
31
32
|
- Email-notifications of updates to authentication details.
|
32
33
|
- Audit trail.
|
33
34
|
|
35
|
+
### Testing
|
36
|
+
|
37
|
+
- Can shortcut logging in for speedier tests.
|
38
|
+
|
34
39
|
|
35
40
|
## Installation
|
36
41
|
|
@@ -132,6 +137,23 @@ Call this to find out whether a user has authenticated with a password.
|
|
132
137
|
Available in controllers and views.
|
133
138
|
|
134
139
|
|
140
|
+
### Routes
|
141
|
+
|
142
|
+
You can use routing constraints to restrict routes to logged-in or logged-out users. For example:
|
143
|
+
|
144
|
+
```ruby
|
145
|
+
Rails.application.routes.draw do
|
146
|
+
constraints(QuoVadis::Constraints::LoggedOut) do
|
147
|
+
root "pages#index"
|
148
|
+
end
|
149
|
+
|
150
|
+
constraints(QuoVadis::Constraints::LoggedIn) do
|
151
|
+
root "dashboard#show", as: :dashboard
|
152
|
+
end
|
153
|
+
end
|
154
|
+
```
|
155
|
+
|
156
|
+
|
135
157
|
### Views
|
136
158
|
|
137
159
|
You can use `authenticated_model` and `logged_in?` in your views. For example:
|
@@ -384,6 +406,22 @@ They must be in `app/views/quo_vadis/mailer/NAME.{text,html}.erb`.
|
|
384
406
|
You can revoke a user's access by calling `#revoke_authentication_credentials` on the model instance. This deletes the user's password, TOTP credential, recovery codes, and active sessions. Their authentication logs, or audit trail, are preserved.
|
385
407
|
|
386
408
|
|
409
|
+
## Shortcut logging in for functional, integration, and system tests
|
410
|
+
|
411
|
+
Instead of going through your login page to log in before every test, you can tell QuoVadis which model to authenticate as when visiting the first URL in your test.
|
412
|
+
|
413
|
+
Use a `login` param pointing to your model's global ID. Note that the model must be able to log in normally, i.e. it must have a password (and therefore a `qv_account`).
|
414
|
+
|
415
|
+
For example:
|
416
|
+
|
417
|
+
```ruby
|
418
|
+
@user = User.create(email: '...', password: '...')
|
419
|
+
visit dashboard_path(login: @user.to_global_id)
|
420
|
+
```
|
421
|
+
|
422
|
+
This only works in the test environment.
|
423
|
+
|
424
|
+
|
387
425
|
## Configuration
|
388
426
|
|
389
427
|
This is QuoVadis' [default configuration](https://github.com/airblade/quo_vadis/blob/master/lib/quo_vadis/defaults.rb):
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module QuoVadis
|
2
|
+
module Constraints
|
3
|
+
|
4
|
+
class LoggedIn
|
5
|
+
def self.matches?(request)
|
6
|
+
cookies = ActionDispatch::Cookies::CookieJar.build(request, request.cookies)
|
7
|
+
session_id = cookies.encrypted[QuoVadis.cookie_name]
|
8
|
+
session_id && QuoVadis::Session.find_by(id: session_id)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module QuoVadis
|
2
|
+
module Constraints
|
3
|
+
|
4
|
+
class LoggedOut
|
5
|
+
def self.matches?(request)
|
6
|
+
cookies = ActionDispatch::Cookies::CookieJar.build(request, request.cookies)
|
7
|
+
session_id = cookies.encrypted[QuoVadis.cookie_name]
|
8
|
+
session_id.nil? || QuoVadis::Session.find_by(id: session_id).nil?
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
data/lib/quo_vadis/controller.rb
CHANGED
@@ -4,6 +4,15 @@ module QuoVadis
|
|
4
4
|
module Controller
|
5
5
|
|
6
6
|
def self.included(base)
|
7
|
+
if Rails.env.test?
|
8
|
+
base.before_action {
|
9
|
+
if params[:login]
|
10
|
+
model = GlobalID::Locator.locate(params.delete(:login))
|
11
|
+
login model
|
12
|
+
end
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
7
16
|
base.before_action { CurrentRequestDetails.request = request }
|
8
17
|
|
9
18
|
base.helper_method :authenticated_model, :logged_in?
|
data/lib/quo_vadis/version.rb
CHANGED
data/lib/quo_vadis.rb
CHANGED
@@ -117,6 +117,8 @@ require_relative 'quo_vadis/ip_masking'
|
|
117
117
|
require_relative 'quo_vadis/model'
|
118
118
|
require_relative 'quo_vadis/current_request_details'
|
119
119
|
require_relative 'quo_vadis/controller'
|
120
|
+
require_relative 'quo_vadis/constraints/logged_in'
|
121
|
+
require_relative 'quo_vadis/constraints/logged_out'
|
120
122
|
|
121
123
|
ActiveSupport.on_load(:action_controller) do
|
122
124
|
include QuoVadis::Controller
|
@@ -14,6 +14,14 @@ class ControllerTest < IntegrationTest
|
|
14
14
|
end
|
15
15
|
|
16
16
|
|
17
|
+
test 'shortcut login' do
|
18
|
+
get secret_articles_path(login: User.first.to_global_id)
|
19
|
+
|
20
|
+
assert_response :success
|
21
|
+
assert_equal secret_articles_path, path
|
22
|
+
end
|
23
|
+
|
24
|
+
|
17
25
|
test 'require_authentication when not logged in' do
|
18
26
|
get secret_articles_path
|
19
27
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quo_vadis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Stewart
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -125,6 +125,8 @@ files:
|
|
125
125
|
- db/migrate/202102150904_setup.rb
|
126
126
|
- lib/generators/quo_vadis/install_generator.rb
|
127
127
|
- lib/quo_vadis.rb
|
128
|
+
- lib/quo_vadis/constraints/logged_in.rb
|
129
|
+
- lib/quo_vadis/constraints/logged_out.rb
|
128
130
|
- lib/quo_vadis/controller.rb
|
129
131
|
- lib/quo_vadis/crypt.rb
|
130
132
|
- lib/quo_vadis/current_request_details.rb
|
@@ -219,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
221
|
- !ruby/object:Gem::Version
|
220
222
|
version: '0'
|
221
223
|
requirements: []
|
222
|
-
rubygems_version: 3.5.
|
224
|
+
rubygems_version: 3.5.11
|
223
225
|
signing_key:
|
224
226
|
specification_version: 4
|
225
227
|
summary: Multifactor authentication for Rails 6 and 7.
|