rodauth-rails 2.1.2 → 2.2.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/README.md +20 -19
- data/lib/generators/rodauth/install_generator.rb +3 -1
- data/lib/generators/rodauth/templates/app/misc/rodauth_app.rb.tt +0 -9
- data/lib/rodauth/rails/auth.rb +1 -1
- data/lib/rodauth/rails/feature/internal_request.rb +8 -0
- data/lib/rodauth/rails/railtie.rb +4 -0
- data/lib/rodauth/rails/version.rb +1 -1
- data/lib/rodauth/rails.rb +1 -17
- data/rodauth-rails.gemspec +2 -2
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 110cd150534a783ea2919ff38d755e8c224535a99e4c9996a90e5312813f3d5c
|
|
4
|
+
data.tar.gz: 1c22dce90c915acad83d68f4a9608177a7d7d50b438c8ada95e059b33f45d70d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e67abaeaf97360f4faa457d637b1269944dedb90a450c77bffa28e315c5de8aeb8624334ee84478fa68f6d3620e6f48d671f29c73e8ddc6447243839b0517b6d
|
|
7
|
+
data.tar.gz: 7f6668732ac4325ba61d68aa3dbb7d295162913867f333eb41329c4cfb14c4850906b7bd3109881e34469eba2737c66112705f397217e8a3f9b3a56d99eaf89b
|
data/README.md
CHANGED
|
@@ -175,23 +175,7 @@ end
|
|
|
175
175
|
|
|
176
176
|
### Requiring authentication
|
|
177
177
|
|
|
178
|
-
|
|
179
|
-
app's routing block, which helps keep the authentication logic encapsulated:
|
|
180
|
-
|
|
181
|
-
```rb
|
|
182
|
-
# app/misc/rodauth_app.rb
|
|
183
|
-
class RodauthApp < Rodauth::Rails::App
|
|
184
|
-
route do |r|
|
|
185
|
-
r.rodauth # route rodauth requests
|
|
186
|
-
|
|
187
|
-
if r.path.start_with?("/dashboard") # /dashboard/* routes
|
|
188
|
-
rodauth.require_account # redirect to login page if not authenticated
|
|
189
|
-
end
|
|
190
|
-
end
|
|
191
|
-
end
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
You can also require authentication at the controller layer:
|
|
178
|
+
It's recommended to require authentication at the controller level:
|
|
195
179
|
|
|
196
180
|
```rb
|
|
197
181
|
class ApplicationController < ActionController::Base
|
|
@@ -208,7 +192,7 @@ class DashboardController < ApplicationController
|
|
|
208
192
|
end
|
|
209
193
|
```
|
|
210
194
|
|
|
211
|
-
|
|
195
|
+
Alternatively, routes can be authenticated at the Rails router level (useful if you're mounting Rack apps):
|
|
212
196
|
|
|
213
197
|
```rb
|
|
214
198
|
# config/routes.rb
|
|
@@ -231,6 +215,22 @@ Rails.application.routes.draw do
|
|
|
231
215
|
end
|
|
232
216
|
```
|
|
233
217
|
|
|
218
|
+
If for whatever reason you'd like to require authentication at the *middleware* level, you can do so within Rodauth app's routing block:
|
|
219
|
+
|
|
220
|
+
```rb
|
|
221
|
+
# app/misc/rodauth_app.rb
|
|
222
|
+
class RodauthApp < Rodauth::Rails::App
|
|
223
|
+
route do |r|
|
|
224
|
+
r.rodauth # route rodauth requests
|
|
225
|
+
|
|
226
|
+
# Avoid using Roda routing matchers like `r.on`, as they can affect paths routed.
|
|
227
|
+
if r.path.match?(%r{\A/dashboard(\.\w+)?(/|\z)}) # /dashboard/* routes with formats
|
|
228
|
+
rodauth.require_account # redirect to login page if not authenticated
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
```
|
|
233
|
+
|
|
234
234
|
### Controller
|
|
235
235
|
|
|
236
236
|
Your Rodauth configuration is linked to a Rails controller, which is primarily used to render views and handle CSRF protection, but will also execute any callbacks and rescue handlers defined on it around Rodauth endpoints.
|
|
@@ -464,7 +464,8 @@ class RodauthApp < Rodauth::Rails::App
|
|
|
464
464
|
r.rodauth # route primary rodauth requests
|
|
465
465
|
r.rodauth(:admin) # route secondary rodauth requests
|
|
466
466
|
|
|
467
|
-
if
|
|
467
|
+
# if you're requiring authentication at the middleware level
|
|
468
|
+
if r.path.match?(%r{\A/admin(\.\w+)?(/|\z)}) # /admin/* routes with format
|
|
468
469
|
rodauth(:admin).require_account
|
|
469
470
|
end
|
|
470
471
|
end
|
|
@@ -26,7 +26,9 @@ module Rodauth
|
|
|
26
26
|
def generate_rodauth_migration
|
|
27
27
|
invoke "rodauth:migration", migration_features,
|
|
28
28
|
name: "create_rodauth",
|
|
29
|
-
prefix: table_prefix
|
|
29
|
+
prefix: table_prefix,
|
|
30
|
+
force: options[:force],
|
|
31
|
+
skip: options[:skip]
|
|
30
32
|
end
|
|
31
33
|
|
|
32
34
|
def create_rodauth_initializer
|
|
@@ -12,15 +12,6 @@ class RodauthApp < Rodauth::Rails::App
|
|
|
12
12
|
<% end -%>
|
|
13
13
|
r.rodauth # route rodauth requests
|
|
14
14
|
|
|
15
|
-
# ==> Authenticating requests
|
|
16
|
-
# Call `rodauth.require_account` for requests that you want to
|
|
17
|
-
# require authentication for. For example:
|
|
18
|
-
#
|
|
19
|
-
# # authenticate /dashboard/* and /account/* requests
|
|
20
|
-
# if r.path.start_with?("/dashboard") || r.path.start_with?("/account")
|
|
21
|
-
# rodauth.require_account
|
|
22
|
-
# end
|
|
23
|
-
|
|
24
15
|
# ==> Secondary configurations
|
|
25
16
|
# r.rodauth(:admin) # route admin rodauth requests
|
|
26
17
|
end
|
data/lib/rodauth/rails/auth.rb
CHANGED
|
@@ -60,6 +60,14 @@ module Rodauth
|
|
|
60
60
|
def _rails_url_options
|
|
61
61
|
defined?(ActionMailer) ? ActionMailer::Base.default_url_options.dup : {}
|
|
62
62
|
end
|
|
63
|
+
|
|
64
|
+
def instance_variables_to_inspect
|
|
65
|
+
variables = instance_variables
|
|
66
|
+
if internal_request? && @internal_request_return_value == self
|
|
67
|
+
variables -= [:@internal_request_block, :@internal_request_return_value, :@internal_request_return_value_set]
|
|
68
|
+
end
|
|
69
|
+
variables
|
|
70
|
+
end
|
|
63
71
|
end
|
|
64
72
|
end
|
|
65
73
|
end
|
|
@@ -7,6 +7,10 @@ require "rails"
|
|
|
7
7
|
module Rodauth
|
|
8
8
|
module Rails
|
|
9
9
|
class Railtie < ::Rails::Railtie
|
|
10
|
+
initializer "rodauth.filter_parameters" do |app|
|
|
11
|
+
app.config.filter_parameters << /\Akey\z/
|
|
12
|
+
end
|
|
13
|
+
|
|
10
14
|
initializer "rodauth.middleware", after: :load_config_initializers do |app|
|
|
11
15
|
if Rodauth::Rails.middleware?
|
|
12
16
|
app.middleware.use Rodauth::Rails::Middleware
|
data/lib/rodauth/rails.rb
CHANGED
|
@@ -38,7 +38,7 @@ module Rodauth
|
|
|
38
38
|
options[:account_id] = account.id
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
auth_class.internal_request_eval(options) do
|
|
42
42
|
if defined?(ActiveRecord::Base) && account.is_a?(ActiveRecord::Base)
|
|
43
43
|
@account = account.attributes_before_type_cast.symbolize_keys
|
|
44
44
|
elsif defined?(Sequel::Model) && account.is_a?(Sequel::Model)
|
|
@@ -46,12 +46,6 @@ module Rodauth
|
|
|
46
46
|
end
|
|
47
47
|
self
|
|
48
48
|
end
|
|
49
|
-
|
|
50
|
-
# clean up inspect output
|
|
51
|
-
instance.remove_instance_variable(:@internal_request_block)
|
|
52
|
-
instance.remove_instance_variable(:@internal_request_return_value)
|
|
53
|
-
|
|
54
|
-
instance
|
|
55
49
|
end
|
|
56
50
|
|
|
57
51
|
def model(name = nil, **options)
|
|
@@ -67,16 +61,6 @@ module Rodauth
|
|
|
67
61
|
end
|
|
68
62
|
end
|
|
69
63
|
|
|
70
|
-
if ::Rails.gem_version >= Gem::Version.new("5.2")
|
|
71
|
-
def secret_key_base
|
|
72
|
-
::Rails.application.secret_key_base
|
|
73
|
-
end
|
|
74
|
-
else
|
|
75
|
-
def secret_key_base
|
|
76
|
-
::Rails.application.secrets.secret_key_base
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
64
|
def configure
|
|
81
65
|
yield self
|
|
82
66
|
end
|
data/rodauth-rails.gemspec
CHANGED
|
@@ -11,12 +11,12 @@ Gem::Specification.new do |spec|
|
|
|
11
11
|
spec.homepage = "https://github.com/janko/rodauth-rails"
|
|
12
12
|
spec.license = "MIT"
|
|
13
13
|
|
|
14
|
-
spec.required_ruby_version = ">=
|
|
14
|
+
spec.required_ruby_version = ">= 3.0"
|
|
15
15
|
|
|
16
16
|
spec.files = Dir["README.md", "LICENSE.txt", "lib/**/*", "*.gemspec"]
|
|
17
17
|
spec.require_paths = ["lib"]
|
|
18
18
|
|
|
19
|
-
spec.add_dependency "railties", ">= 5.
|
|
19
|
+
spec.add_dependency "railties", ">= 5.2"
|
|
20
20
|
spec.add_dependency "rodauth", "~> 2.36"
|
|
21
21
|
spec.add_dependency "roda", "~> 3.76"
|
|
22
22
|
spec.add_dependency "rodauth-model", "~> 0.2"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rodauth-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Janko Marohnić
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: '5.
|
|
18
|
+
version: '5.2'
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: '5.
|
|
25
|
+
version: '5.2'
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: rodauth
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -350,14 +350,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
350
350
|
requirements:
|
|
351
351
|
- - ">="
|
|
352
352
|
- !ruby/object:Gem::Version
|
|
353
|
-
version: '
|
|
353
|
+
version: '3.0'
|
|
354
354
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
355
355
|
requirements:
|
|
356
356
|
- - ">="
|
|
357
357
|
- !ruby/object:Gem::Version
|
|
358
358
|
version: '0'
|
|
359
359
|
requirements: []
|
|
360
|
-
rubygems_version:
|
|
360
|
+
rubygems_version: 4.0.13
|
|
361
361
|
specification_version: 4
|
|
362
362
|
summary: Provides Rails integration for Rodauth authentication framework.
|
|
363
363
|
test_files: []
|