authie 4.0.0.rc3 → 4.0.0.rc6
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/lib/authie/controller_delegate.rb +18 -8
- data/lib/authie/controller_extension.rb +7 -1
- data/lib/authie/session.rb +7 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f0ed5ff2724edcadbe4c3da00f495f61c49fb8527a9a3ea990d6cbb0d1b3481
|
4
|
+
data.tar.gz: f3c621bd0cd8561123e39b508647d1bc5b356038928682d1b541635d9913c9cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f326f7e0aee77baccff01544c98730902fd77c722c803b49257bad520eb6f5340ab00bf585050b6a5d447409f86954147ec9e701d9af404948cb8f7977008c78
|
7
|
+
data.tar.gz: 55da617f47e858b869fb4e3f1afb14a45dd3ff2a661656db89906bdf66fd2c2a785ac70163de3e60e342f3e91601fcb058ff7a77663f840502268e77a224d7d5
|
@@ -9,10 +9,13 @@ module Authie
|
|
9
9
|
# The controller delegate implements methods that can be used by a controller. These are then
|
10
10
|
# extended into controllers as needed (see ControllerExtension).
|
11
11
|
class ControllerDelegate
|
12
|
+
attr_accessor :touch_auth_session_enabled
|
13
|
+
|
12
14
|
# @param controller [ActionController::Base]
|
13
15
|
# @return [Authie::ControllerDelegate]
|
14
16
|
def initialize(controller)
|
15
17
|
@controller = controller
|
18
|
+
@touch_auth_session_enabled = true
|
16
19
|
end
|
17
20
|
|
18
21
|
# Sets a browser ID. This must be performed on any page request where AUthie will be used.
|
@@ -36,18 +39,25 @@ module Authie
|
|
36
39
|
proposed_browser_id
|
37
40
|
end
|
38
41
|
|
39
|
-
#
|
40
|
-
#
|
41
|
-
# it will reteurn false if there is no session/not logged in. It is safe to run this on
|
42
|
-
# all requests even if there is no session.
|
42
|
+
# Validate the auth session to ensure that it is current validate and raise an error if it
|
43
|
+
# is not suitable for use.
|
43
44
|
#
|
44
45
|
# @return [Authie::Session, false]
|
45
|
-
def
|
46
|
-
return auth_session.
|
46
|
+
def validate_auth_session
|
47
|
+
return auth_session.validate if logged_in?
|
47
48
|
|
48
49
|
false
|
49
50
|
end
|
50
51
|
|
52
|
+
# Touch the session to update details on the latest activity.
|
53
|
+
#
|
54
|
+
# @return [Authie::Session, false]
|
55
|
+
def touch_auth_session
|
56
|
+
yield if block_given?
|
57
|
+
ensure
|
58
|
+
auth_session.touch if @touch_auth_session_enabled && logged_in?
|
59
|
+
end
|
60
|
+
|
51
61
|
# Return the user for the currently logged in user or nil if no user is logged in
|
52
62
|
#
|
53
63
|
# @return [ActiveRecord::Base, nil]
|
@@ -61,9 +71,9 @@ module Authie
|
|
61
71
|
# will be invalidated.
|
62
72
|
#
|
63
73
|
# @return [Authie::Session, nil]
|
64
|
-
def create_auth_session(user)
|
74
|
+
def create_auth_session(user, **kwargs)
|
65
75
|
if user
|
66
|
-
@auth_session = Authie::Session.start(@controller, user: user)
|
76
|
+
@auth_session = Authie::Session.start(@controller, user: user, **kwargs)
|
67
77
|
return @auth_session
|
68
78
|
end
|
69
79
|
|
@@ -7,9 +7,11 @@ module Authie
|
|
7
7
|
class << self
|
8
8
|
def included(base)
|
9
9
|
base.helper_method :logged_in?, :current_user, :auth_session
|
10
|
-
base.before_action :set_browser_id, :
|
10
|
+
base.before_action :set_browser_id, :validate_auth_session
|
11
|
+
base.around_action :touch_auth_session
|
11
12
|
|
12
13
|
base.delegate :set_browser_id, to: :auth_session_delegate
|
14
|
+
base.delegate :validate_auth_session, to: :auth_session_delegate
|
13
15
|
base.delegate :touch_auth_session, to: :auth_session_delegate
|
14
16
|
base.delegate :current_user, to: :auth_session_delegate
|
15
17
|
base.delegate :create_auth_session, to: :auth_session_delegate
|
@@ -24,5 +26,9 @@ module Authie
|
|
24
26
|
def auth_session_delegate
|
25
27
|
@auth_session_delegate ||= Authie::ControllerDelegate.new(self)
|
26
28
|
end
|
29
|
+
|
30
|
+
def skip_touch_auth_session!
|
31
|
+
auth_session_delegate.touch_auth_session_enabled = false
|
32
|
+
end
|
27
33
|
end
|
28
34
|
end
|
data/lib/authie/session.rb
CHANGED
@@ -88,7 +88,6 @@ module Authie
|
|
88
88
|
# @raises [ActiveRecord::RecordInvalid]
|
89
89
|
# @return [Authie::Session]
|
90
90
|
def touch
|
91
|
-
validate
|
92
91
|
@session.last_activity_at = Time.now
|
93
92
|
@session.last_activity_ip = @controller.request.ip
|
94
93
|
@session.last_activity_path = @controller.request.path
|
@@ -206,20 +205,22 @@ module Authie
|
|
206
205
|
# Create a new session within the given controller for the
|
207
206
|
#
|
208
207
|
# @param controller [ActionController::Base]
|
209
|
-
# @
|
208
|
+
# @param user [ActiveRecord::Base] user
|
209
|
+
# @param persistent [Boolean] create a persistent session
|
210
210
|
# @return [Authie::Session]
|
211
|
-
def start(controller,
|
211
|
+
def start(controller, user:, persistent: false, see_password: false, **params)
|
212
212
|
cookies = controller.send(:cookies)
|
213
213
|
SessionModel.active.where(browser_id: cookies[:browser_id]).each(&:invalidate!)
|
214
|
-
user_object = params.delete(:user)
|
215
214
|
|
216
215
|
session = SessionModel.new(params)
|
217
|
-
session.user =
|
216
|
+
session.user = user
|
218
217
|
session.browser_id = cookies[:browser_id]
|
219
218
|
session.login_at = Time.now
|
220
219
|
session.login_ip = controller.request.ip
|
221
220
|
session.host = controller.request.host
|
222
221
|
session.user_agent = controller.request.user_agent
|
222
|
+
session.expires_at = Time.now + Authie.config.persistent_session_length if persistent
|
223
|
+
session.password_seen_at = Time.now if see_password
|
223
224
|
session.save!
|
224
225
|
|
225
226
|
new(controller, session).start
|
@@ -261,6 +262,7 @@ module Authie
|
|
261
262
|
delegate :active?, to: :session
|
262
263
|
delegate :browser_id, to: :session
|
263
264
|
delegate :expired?, to: :session
|
265
|
+
delegate :expires_at, to: :session
|
264
266
|
delegate :first_session_for_browser?, to: :session
|
265
267
|
delegate :first_session_for_ip?, to: :session
|
266
268
|
delegate :get, to: :session
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.0.
|
4
|
+
version: 4.0.0.rc6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Cooke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|