authie 4.0.0.rc10 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/db/migrate/20141012174250_create_authie_sessions.rb +2 -2
- data/db/migrate/20141013115205_add_indexes_to_authie_sessions.rb +1 -1
- data/db/migrate/20150109144120_add_parent_id_to_authie_sessions.rb +2 -2
- data/db/migrate/20150305135400_add_two_factor_auth_fields_to_authie.rb +1 -1
- data/db/migrate/20170417170000_add_token_hashes_to_authie_sessions.rb +1 -1
- data/db/migrate/20170421174100_add_index_to_token_hashes_on_authie_sessions.rb +1 -1
- data/db/migrate/20180215152200_add_host_to_authie_sessions.rb +1 -1
- data/db/migrate/20220502180100_add_two_factor_required_to_sessions.rb +1 -1
- data/lib/authie/controller_delegate.rb +10 -13
- data/lib/authie/controller_extension.rb +2 -1
- data/lib/authie/session.rb +16 -10
- data/lib/authie/session_model.rb +3 -1
- metadata +5 -193
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3fc31edba5c9cfea934c40b4ac410c942f5d0fcb75a236a9a0f8bd671556058a
|
4
|
+
data.tar.gz: 6ebbf8156b7092e358c4ed08f2d403a002c4f8930cc7e5b5bfc375cd5bc6e718
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21b86b8a69c1878736de93952f5b4e88bcb1080470f3b3df9f1e12087a29996f71dc39177020747b2e31fff6a39da88ff560e168b35ce61e602e77eb68c7e45b
|
7
|
+
data.tar.gz: 4cf16e7b8af0f80d68cae494c59f7f0c3722c92475c80b47ad2ea4f7b719099ad8e053deb708ee90fe1996db4065869f1f98c92121987cbf68bcae159001465e
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
class CreateAuthieSessions < ActiveRecord::Migration[
|
3
|
+
class CreateAuthieSessions < ActiveRecord::Migration[6.1]
|
4
4
|
def change
|
5
5
|
create_table :authie_sessions do |t|
|
6
6
|
t.string :token, :browser_id
|
7
|
-
t.
|
7
|
+
t.bigint :user_id
|
8
8
|
t.boolean :active, default: true
|
9
9
|
t.text :data
|
10
10
|
t.datetime :expires_at
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
class AddIndexesToAuthieSessions < ActiveRecord::Migration[
|
3
|
+
class AddIndexesToAuthieSessions < ActiveRecord::Migration[6.1]
|
4
4
|
def change
|
5
5
|
add_column :authie_sessions, :user_type, :string
|
6
6
|
add_index :authie_sessions, :token, length: 10
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
class AddParentIdToAuthieSessions < ActiveRecord::Migration[
|
3
|
+
class AddParentIdToAuthieSessions < ActiveRecord::Migration[6.1]
|
4
4
|
def change
|
5
|
-
add_column :authie_sessions, :parent_id, :
|
5
|
+
add_column :authie_sessions, :parent_id, :bigint
|
6
6
|
end
|
7
7
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
class AddTwoFactorAuthFieldsToAuthie < ActiveRecord::Migration[
|
3
|
+
class AddTwoFactorAuthFieldsToAuthie < ActiveRecord::Migration[6.1]
|
4
4
|
def change
|
5
5
|
add_column :authie_sessions, :two_factored_at, :datetime
|
6
6
|
add_column :authie_sessions, :two_factored_ip, :string
|
@@ -46,9 +46,9 @@ module Authie
|
|
46
46
|
#
|
47
47
|
# @return [Authie::Session, false]
|
48
48
|
def validate_auth_session
|
49
|
-
return
|
49
|
+
return false unless logged_in?
|
50
50
|
|
51
|
-
|
51
|
+
auth_session.validate
|
52
52
|
end
|
53
53
|
|
54
54
|
# Touch the session to update details on the latest activity.
|
@@ -74,13 +74,12 @@ module Authie
|
|
74
74
|
#
|
75
75
|
# @return [Authie::Session, nil]
|
76
76
|
def create_auth_session(user, **kwargs)
|
77
|
-
if user
|
78
|
-
|
79
|
-
return
|
77
|
+
if user.nil?
|
78
|
+
invalidate_auth_session
|
79
|
+
return nil
|
80
80
|
end
|
81
81
|
|
82
|
-
|
83
|
-
nil
|
82
|
+
@auth_session = Authie::Session.start(@controller, user: user, **kwargs)
|
84
83
|
end
|
85
84
|
|
86
85
|
# Invalidate the existing auth session if one exists. Return true if a sesion has been invalidated
|
@@ -88,13 +87,11 @@ module Authie
|
|
88
87
|
#
|
89
88
|
# @return [Boolean]
|
90
89
|
def invalidate_auth_session
|
91
|
-
|
92
|
-
auth_session.invalidate
|
93
|
-
@auth_session = nil
|
94
|
-
return true
|
95
|
-
end
|
90
|
+
return false unless logged_in?
|
96
91
|
|
97
|
-
|
92
|
+
auth_session.invalidate
|
93
|
+
@auth_session = nil
|
94
|
+
true
|
98
95
|
end
|
99
96
|
|
100
97
|
# Is anyone currently logged in? Return true if there is an auth session present.
|
@@ -6,7 +6,8 @@ module Authie
|
|
6
6
|
module ControllerExtension
|
7
7
|
class << self
|
8
8
|
def included(base)
|
9
|
-
base.helper_method :logged_in?, :current_user, :auth_session
|
9
|
+
base.helper_method :logged_in?, :current_user, :auth_session if base.respond_to?(:helper_method)
|
10
|
+
|
10
11
|
base.before_action :set_browser_id, :validate_auth_session
|
11
12
|
base.around_action :touch_auth_session
|
12
13
|
|
data/lib/authie/session.rb
CHANGED
@@ -13,7 +13,14 @@ module Authie
|
|
13
13
|
attr_reader :session
|
14
14
|
|
15
15
|
# A parent class that encapsulates all session validity errors.
|
16
|
-
class ValidityError < Error
|
16
|
+
class ValidityError < Error
|
17
|
+
attr_reader :session
|
18
|
+
|
19
|
+
def initialize(message, session = nil)
|
20
|
+
super(message)
|
21
|
+
@session = session
|
22
|
+
end
|
23
|
+
end
|
17
24
|
|
18
25
|
# Raised when a session is used but it is no longer active
|
19
26
|
class InactiveSession < ValidityError; end
|
@@ -145,7 +152,6 @@ module Authie
|
|
145
152
|
|
146
153
|
private
|
147
154
|
|
148
|
-
# rubocop:disable Naming/AccessorMethodName
|
149
155
|
def set_cookie(value = @session.temporary_token)
|
150
156
|
cookies[:user_session] = {
|
151
157
|
value: value,
|
@@ -156,7 +162,6 @@ module Authie
|
|
156
162
|
Authie.notify(:cookie_updated, session: session)
|
157
163
|
true
|
158
164
|
end
|
159
|
-
# rubocop:enable Naming/AccessorMethodName
|
160
165
|
|
161
166
|
def cookies
|
162
167
|
@controller.send(:cookies)
|
@@ -164,9 +169,9 @@ module Authie
|
|
164
169
|
|
165
170
|
def validate_browser_id
|
166
171
|
if cookies[:browser_id] != @session.browser_id
|
167
|
-
invalidate
|
168
172
|
Authie.notify(:browser_id_mismatch_error, session: self)
|
169
|
-
|
173
|
+
invalidate
|
174
|
+
raise BrowserMismatch.new('Browser ID mismatch', self)
|
170
175
|
end
|
171
176
|
|
172
177
|
self
|
@@ -176,7 +181,7 @@ module Authie
|
|
176
181
|
unless @session.active?
|
177
182
|
invalidate
|
178
183
|
Authie.notify(:invalid_session_error, session: self)
|
179
|
-
raise InactiveSession
|
184
|
+
raise InactiveSession.new('Session is no longer active', self)
|
180
185
|
end
|
181
186
|
|
182
187
|
self
|
@@ -186,7 +191,7 @@ module Authie
|
|
186
191
|
if @session.expired?
|
187
192
|
invalidate
|
188
193
|
Authie.notify(:expired_session_error, session: self)
|
189
|
-
raise ExpiredSession
|
194
|
+
raise ExpiredSession.new('Persistent session has expired', self)
|
190
195
|
end
|
191
196
|
|
192
197
|
self
|
@@ -195,8 +200,8 @@ module Authie
|
|
195
200
|
def validate_inactivity
|
196
201
|
if @session.inactive?
|
197
202
|
invalidate
|
198
|
-
Authie.notify(:inactive_session_error, session:
|
199
|
-
raise InactiveSession
|
203
|
+
Authie.notify(:inactive_session_error, session: self)
|
204
|
+
raise InactiveSession.new('Non-persistent session has expired', self)
|
200
205
|
end
|
201
206
|
|
202
207
|
self
|
@@ -206,7 +211,8 @@ module Authie
|
|
206
211
|
if @session.host && @session.host != @controller.request.host
|
207
212
|
invalidate
|
208
213
|
Authie.notify(:host_mismatch_error, session: self)
|
209
|
-
raise HostMismatch
|
214
|
+
raise HostMismatch.new("Session was created on #{@session.host} but accessed using #{@controller.request.host}",
|
215
|
+
self)
|
210
216
|
end
|
211
217
|
|
212
218
|
self
|
data/lib/authie/session_model.rb
CHANGED
@@ -63,8 +63,10 @@ module Authie
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def invalidate!
|
66
|
+
active_now = active?
|
66
67
|
self.active = false
|
67
68
|
save!
|
69
|
+
Authie.notify(:session_invalidate, session: self) if active_now
|
68
70
|
true
|
69
71
|
end
|
70
72
|
|
@@ -79,7 +81,7 @@ module Authie
|
|
79
81
|
end
|
80
82
|
|
81
83
|
def invalidate_others!
|
82
|
-
self.class.where('id != ?', id).for_user(user).each(&:invalidate!)
|
84
|
+
self.class.where('id != ?', id).active.for_user(user).each(&:invalidate!)
|
83
85
|
end
|
84
86
|
|
85
87
|
# Have we seen the user's password recently in this sesion?
|
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
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Cooke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -30,194 +30,6 @@ dependencies:
|
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '8.0'
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: appraisal
|
35
|
-
requirement: !ruby/object:Gem::Requirement
|
36
|
-
requirements:
|
37
|
-
- - '='
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: 2.4.1
|
40
|
-
type: :development
|
41
|
-
prerelease: false
|
42
|
-
version_requirements: !ruby/object:Gem::Requirement
|
43
|
-
requirements:
|
44
|
-
- - '='
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 2.4.1
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: rails
|
49
|
-
requirement: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - ">="
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '5.0'
|
54
|
-
- - "<"
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: '8.0'
|
57
|
-
type: :development
|
58
|
-
prerelease: false
|
59
|
-
version_requirements: !ruby/object:Gem::Requirement
|
60
|
-
requirements:
|
61
|
-
- - ">="
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
version: '5.0'
|
64
|
-
- - "<"
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version: '8.0'
|
67
|
-
- !ruby/object:Gem::Dependency
|
68
|
-
name: rspec
|
69
|
-
requirement: !ruby/object:Gem::Requirement
|
70
|
-
requirements:
|
71
|
-
- - ">="
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
version: '0'
|
74
|
-
type: :development
|
75
|
-
prerelease: false
|
76
|
-
version_requirements: !ruby/object:Gem::Requirement
|
77
|
-
requirements:
|
78
|
-
- - ">="
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
version: '0'
|
81
|
-
- !ruby/object:Gem::Dependency
|
82
|
-
name: rspec-core
|
83
|
-
requirement: !ruby/object:Gem::Requirement
|
84
|
-
requirements:
|
85
|
-
- - ">="
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
version: '0'
|
88
|
-
type: :development
|
89
|
-
prerelease: false
|
90
|
-
version_requirements: !ruby/object:Gem::Requirement
|
91
|
-
requirements:
|
92
|
-
- - ">="
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
version: '0'
|
95
|
-
- !ruby/object:Gem::Dependency
|
96
|
-
name: rspec-expectations
|
97
|
-
requirement: !ruby/object:Gem::Requirement
|
98
|
-
requirements:
|
99
|
-
- - ">="
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
version: '0'
|
102
|
-
type: :development
|
103
|
-
prerelease: false
|
104
|
-
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
requirements:
|
106
|
-
- - ">="
|
107
|
-
- !ruby/object:Gem::Version
|
108
|
-
version: '0'
|
109
|
-
- !ruby/object:Gem::Dependency
|
110
|
-
name: rspec-mocks
|
111
|
-
requirement: !ruby/object:Gem::Requirement
|
112
|
-
requirements:
|
113
|
-
- - ">="
|
114
|
-
- !ruby/object:Gem::Version
|
115
|
-
version: '0'
|
116
|
-
type: :development
|
117
|
-
prerelease: false
|
118
|
-
version_requirements: !ruby/object:Gem::Requirement
|
119
|
-
requirements:
|
120
|
-
- - ">="
|
121
|
-
- !ruby/object:Gem::Version
|
122
|
-
version: '0'
|
123
|
-
- !ruby/object:Gem::Dependency
|
124
|
-
name: rspec-rails
|
125
|
-
requirement: !ruby/object:Gem::Requirement
|
126
|
-
requirements:
|
127
|
-
- - ">="
|
128
|
-
- !ruby/object:Gem::Version
|
129
|
-
version: '0'
|
130
|
-
type: :development
|
131
|
-
prerelease: false
|
132
|
-
version_requirements: !ruby/object:Gem::Requirement
|
133
|
-
requirements:
|
134
|
-
- - ">="
|
135
|
-
- !ruby/object:Gem::Version
|
136
|
-
version: '0'
|
137
|
-
- !ruby/object:Gem::Dependency
|
138
|
-
name: rubocop
|
139
|
-
requirement: !ruby/object:Gem::Requirement
|
140
|
-
requirements:
|
141
|
-
- - '='
|
142
|
-
- !ruby/object:Gem::Version
|
143
|
-
version: 1.17.0
|
144
|
-
type: :development
|
145
|
-
prerelease: false
|
146
|
-
version_requirements: !ruby/object:Gem::Requirement
|
147
|
-
requirements:
|
148
|
-
- - '='
|
149
|
-
- !ruby/object:Gem::Version
|
150
|
-
version: 1.17.0
|
151
|
-
- !ruby/object:Gem::Dependency
|
152
|
-
name: simplecov
|
153
|
-
requirement: !ruby/object:Gem::Requirement
|
154
|
-
requirements:
|
155
|
-
- - ">="
|
156
|
-
- !ruby/object:Gem::Version
|
157
|
-
version: '0'
|
158
|
-
type: :development
|
159
|
-
prerelease: false
|
160
|
-
version_requirements: !ruby/object:Gem::Requirement
|
161
|
-
requirements:
|
162
|
-
- - ">="
|
163
|
-
- !ruby/object:Gem::Version
|
164
|
-
version: '0'
|
165
|
-
- !ruby/object:Gem::Dependency
|
166
|
-
name: simplecov-console
|
167
|
-
requirement: !ruby/object:Gem::Requirement
|
168
|
-
requirements:
|
169
|
-
- - ">="
|
170
|
-
- !ruby/object:Gem::Version
|
171
|
-
version: '0'
|
172
|
-
type: :development
|
173
|
-
prerelease: false
|
174
|
-
version_requirements: !ruby/object:Gem::Requirement
|
175
|
-
requirements:
|
176
|
-
- - ">="
|
177
|
-
- !ruby/object:Gem::Version
|
178
|
-
version: '0'
|
179
|
-
- !ruby/object:Gem::Dependency
|
180
|
-
name: solargraph
|
181
|
-
requirement: !ruby/object:Gem::Requirement
|
182
|
-
requirements:
|
183
|
-
- - ">="
|
184
|
-
- !ruby/object:Gem::Version
|
185
|
-
version: '0'
|
186
|
-
type: :development
|
187
|
-
prerelease: false
|
188
|
-
version_requirements: !ruby/object:Gem::Requirement
|
189
|
-
requirements:
|
190
|
-
- - ">="
|
191
|
-
- !ruby/object:Gem::Version
|
192
|
-
version: '0'
|
193
|
-
- !ruby/object:Gem::Dependency
|
194
|
-
name: sqlite3
|
195
|
-
requirement: !ruby/object:Gem::Requirement
|
196
|
-
requirements:
|
197
|
-
- - '='
|
198
|
-
- !ruby/object:Gem::Version
|
199
|
-
version: 1.4.2
|
200
|
-
type: :development
|
201
|
-
prerelease: false
|
202
|
-
version_requirements: !ruby/object:Gem::Requirement
|
203
|
-
requirements:
|
204
|
-
- - '='
|
205
|
-
- !ruby/object:Gem::Version
|
206
|
-
version: 1.4.2
|
207
|
-
- !ruby/object:Gem::Dependency
|
208
|
-
name: timecop
|
209
|
-
requirement: !ruby/object:Gem::Requirement
|
210
|
-
requirements:
|
211
|
-
- - ">="
|
212
|
-
- !ruby/object:Gem::Version
|
213
|
-
version: '0'
|
214
|
-
type: :development
|
215
|
-
prerelease: false
|
216
|
-
version_requirements: !ruby/object:Gem::Requirement
|
217
|
-
requirements:
|
218
|
-
- - ">="
|
219
|
-
- !ruby/object:Gem::Version
|
220
|
-
version: '0'
|
221
33
|
description: A Rails library for storing user sessions in a backend database
|
222
34
|
email:
|
223
35
|
- me@adamcooke.io
|
@@ -259,11 +71,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
259
71
|
version: '0'
|
260
72
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
261
73
|
requirements:
|
262
|
-
- - "
|
74
|
+
- - ">="
|
263
75
|
- !ruby/object:Gem::Version
|
264
|
-
version:
|
76
|
+
version: '0'
|
265
77
|
requirements: []
|
266
|
-
rubygems_version: 3.3.
|
78
|
+
rubygems_version: 3.3.26
|
267
79
|
signing_key:
|
268
80
|
specification_version: 4
|
269
81
|
summary: A Rails library for storing user sessions in a backend database
|