current_session 0.1.5 → 0.1.7
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/.rubocop.yml +1 -1
- data/Gemfile +5 -3
- data/Gemfile.lock +34 -24
- data/lib/current_session/auth_method.rb +10 -26
- data/lib/current_session/base.rb +1 -42
- data/lib/current_session/dsl.rb +35 -0
- data/lib/current_session/interface.rb +5 -24
- data/lib/current_session/session_method.rb +25 -25
- data/lib/current_session/version.rb +1 -1
- data/lib/current_session.rb +3 -3
- metadata +4 -7
- data/lib/current_session/session_methods/active_record_session.rb +0 -35
- data/lib/current_session/session_methods/env_session.rb +0 -32
- data/lib/current_session/session_methods/uid_session.rb +0 -21
- data/lib/current_session/session_methods.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 505b1421a5df8b13c947388a55f0af6224ebae0d7e61c552292896e53a7ffae8
|
4
|
+
data.tar.gz: 1d047d2c47aff4e1665a743d7d38cb5b964493525d0c3f611fcac36f22bc2ec9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fde9c27a98d38fd4bcc0a55c82921cfd19c9525538a9a618d91a575c287fe8611bac043f455c25d62e6b2703d03c962fa2b9e4aaa50f9a3a2b91eb087e41fbc6
|
7
|
+
data.tar.gz: c6fb18a168a5cdaf575d63ddcac4ef35bf9ba3943a15a76615e77301e63c2953117b7231e501f1e89381cc7850e19251ae6f32c1b691b3d5c6df0a6d93f97e8f
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
@@ -5,8 +5,10 @@ source "https://rubygems.org"
|
|
5
5
|
# Specify your gem's dependencies in current_user_omniauth.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
-
gem "rake"
|
8
|
+
gem "rake"
|
9
9
|
|
10
|
-
gem "rspec"
|
10
|
+
gem "rspec"
|
11
11
|
|
12
|
-
gem "rubocop"
|
12
|
+
gem "rubocop"
|
13
|
+
gem "rubocop-performance"
|
14
|
+
gem "rubocop-rspec"
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
current_session (0.1.
|
4
|
+
current_session (0.1.7)
|
5
5
|
activesupport (>= 6.0.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -26,7 +26,7 @@ GEM
|
|
26
26
|
hashie (5.0.0)
|
27
27
|
i18n (1.12.0)
|
28
28
|
concurrent-ruby (~> 1.0)
|
29
|
-
json (2.6.
|
29
|
+
json (2.6.3)
|
30
30
|
method_source (1.0.0)
|
31
31
|
minitest (5.16.3)
|
32
32
|
omniauth (2.1.0)
|
@@ -34,43 +34,48 @@ GEM
|
|
34
34
|
rack (>= 2.2.3)
|
35
35
|
rack-protection
|
36
36
|
parallel (1.22.1)
|
37
|
-
parser (3.1.
|
37
|
+
parser (3.1.3.0)
|
38
38
|
ast (~> 2.4.1)
|
39
39
|
pry (0.14.1)
|
40
40
|
coderay (~> 1.1)
|
41
41
|
method_source (~> 1.0)
|
42
|
-
rack (3.0.
|
43
|
-
rack-protection (3.0.
|
42
|
+
rack (3.0.2)
|
43
|
+
rack-protection (3.0.5)
|
44
44
|
rack
|
45
45
|
rainbow (3.1.1)
|
46
46
|
rake (13.0.6)
|
47
|
-
regexp_parser (2.6.
|
47
|
+
regexp_parser (2.6.1)
|
48
48
|
rexml (3.2.5)
|
49
|
-
rspec (3.
|
50
|
-
rspec-core (~> 3.
|
51
|
-
rspec-expectations (~> 3.
|
52
|
-
rspec-mocks (~> 3.
|
53
|
-
rspec-core (3.
|
54
|
-
rspec-support (~> 3.
|
55
|
-
rspec-expectations (3.
|
49
|
+
rspec (3.12.0)
|
50
|
+
rspec-core (~> 3.12.0)
|
51
|
+
rspec-expectations (~> 3.12.0)
|
52
|
+
rspec-mocks (~> 3.12.0)
|
53
|
+
rspec-core (3.12.0)
|
54
|
+
rspec-support (~> 3.12.0)
|
55
|
+
rspec-expectations (3.12.1)
|
56
56
|
diff-lcs (>= 1.2.0, < 2.0)
|
57
|
-
rspec-support (~> 3.
|
58
|
-
rspec-mocks (3.
|
57
|
+
rspec-support (~> 3.12.0)
|
58
|
+
rspec-mocks (3.12.1)
|
59
59
|
diff-lcs (>= 1.2.0, < 2.0)
|
60
|
-
rspec-support (~> 3.
|
61
|
-
rspec-support (3.
|
62
|
-
rubocop (1.
|
60
|
+
rspec-support (~> 3.12.0)
|
61
|
+
rspec-support (3.12.0)
|
62
|
+
rubocop (1.41.1)
|
63
63
|
json (~> 2.3)
|
64
64
|
parallel (~> 1.10)
|
65
65
|
parser (>= 3.1.2.1)
|
66
66
|
rainbow (>= 2.2.2, < 4.0)
|
67
67
|
regexp_parser (>= 1.8, < 3.0)
|
68
68
|
rexml (>= 3.2.5, < 4.0)
|
69
|
-
rubocop-ast (>= 1.
|
69
|
+
rubocop-ast (>= 1.23.0, < 2.0)
|
70
70
|
ruby-progressbar (~> 1.7)
|
71
71
|
unicode-display_width (>= 1.4.0, < 3.0)
|
72
|
-
rubocop-ast (1.
|
72
|
+
rubocop-ast (1.24.0)
|
73
73
|
parser (>= 3.1.1.0)
|
74
|
+
rubocop-performance (1.15.1)
|
75
|
+
rubocop (>= 1.7.0, < 2.0)
|
76
|
+
rubocop-ast (>= 0.4.0)
|
77
|
+
rubocop-rspec (2.16.0)
|
78
|
+
rubocop (~> 1.33)
|
74
79
|
ruby-progressbar (1.11.0)
|
75
80
|
simplecov (0.21.2)
|
76
81
|
docile (~> 1.1)
|
@@ -78,13 +83,16 @@ GEM
|
|
78
83
|
simplecov_json_formatter (~> 0.1)
|
79
84
|
simplecov-html (0.12.3)
|
80
85
|
simplecov_json_formatter (0.1.4)
|
81
|
-
sqlite3 (1.5.
|
86
|
+
sqlite3 (1.5.4-arm64-darwin)
|
87
|
+
sqlite3 (1.5.4-x86_64-linux)
|
82
88
|
tzinfo (2.0.5)
|
83
89
|
concurrent-ruby (~> 1.0)
|
84
90
|
unicode-display_width (2.3.0)
|
85
91
|
|
86
92
|
PLATFORMS
|
87
93
|
arm64-darwin-20
|
94
|
+
arm64-darwin-21
|
95
|
+
x86_64-linux
|
88
96
|
|
89
97
|
DEPENDENCIES
|
90
98
|
activerecord
|
@@ -92,9 +100,11 @@ DEPENDENCIES
|
|
92
100
|
ffaker
|
93
101
|
omniauth
|
94
102
|
pry
|
95
|
-
rake
|
96
|
-
rspec
|
97
|
-
rubocop
|
103
|
+
rake
|
104
|
+
rspec
|
105
|
+
rubocop
|
106
|
+
rubocop-performance
|
107
|
+
rubocop-rspec
|
98
108
|
simplecov
|
99
109
|
sqlite3
|
100
110
|
|
@@ -2,34 +2,11 @@
|
|
2
2
|
|
3
3
|
module CurrentSession
|
4
4
|
#
|
5
|
-
#
|
5
|
+
# auth method
|
6
6
|
#
|
7
7
|
class AuthMethod
|
8
|
-
|
9
|
-
|
10
|
-
class FindBy < self
|
11
|
-
def call(&block)
|
12
|
-
find_by_auth.try(&block)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
class FindOrCreateBy < self
|
17
|
-
def call(&block)
|
18
|
-
find_or_create_by_auth.try(&block)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.new_auth_class(auth_methods_module)
|
23
|
-
new_auth_class =
|
24
|
-
if auth_methods_module.method_defined?(:find_by_auth)
|
25
|
-
Class.new(CurrentSession::AuthMethod::FindBy) { include auth_methods_module }
|
26
|
-
elsif auth_methods_module.method_defined?(:find_or_create_by_auth)
|
27
|
-
Class.new(CurrentSession::AuthMethod::FindOrCreateBy) { include auth_methods_module }
|
28
|
-
else
|
29
|
-
fail NotImplementedError, "You must implement find_by_auth or find_or_create_by_auth"
|
30
|
-
end
|
31
|
-
new_auth_class.user_class = user_class
|
32
|
-
new_auth_class
|
8
|
+
def self.new_class(methods)
|
9
|
+
Class.new(self) { include methods }
|
33
10
|
end
|
34
11
|
|
35
12
|
def initialize(request)
|
@@ -40,5 +17,12 @@ module CurrentSession
|
|
40
17
|
def auth
|
41
18
|
request.env["omniauth.auth"]
|
42
19
|
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# @return User
|
23
|
+
#
|
24
|
+
def connect
|
25
|
+
fail NotImplementedError, "You must implement #{self.class}##{__method__}"
|
26
|
+
end
|
43
27
|
end
|
44
28
|
end
|
data/lib/current_session/base.rb
CHANGED
@@ -6,48 +6,7 @@ module CurrentSession
|
|
6
6
|
#
|
7
7
|
class Base < ActiveSupport::CurrentAttributes
|
8
8
|
include CurrentSession::Interface
|
9
|
+
include CurrentSession::Dsl
|
9
10
|
attribute :current_user
|
10
|
-
|
11
|
-
class << self
|
12
|
-
attr_accessor :session_token_class
|
13
|
-
attr_reader :user_class
|
14
|
-
|
15
|
-
def user_class=(user_class)
|
16
|
-
@user_class = user_class
|
17
|
-
@auth_class.user_class = user_class if @auth_class
|
18
|
-
end
|
19
|
-
|
20
|
-
def current_time(_)
|
21
|
-
Time.current
|
22
|
-
end
|
23
|
-
|
24
|
-
def session_methods=(session_methods)
|
25
|
-
@session_methods = session_methods
|
26
|
-
@session_class = CurrentSession::SessionMethod.new_session_class(session_methods)
|
27
|
-
end
|
28
|
-
|
29
|
-
def session_methods(&block)
|
30
|
-
if block
|
31
|
-
@session_methods = Module.new(&block)
|
32
|
-
@session_class = CurrentSession::SessionMethod.new_session_class(session_methods)
|
33
|
-
else
|
34
|
-
@session_methods
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def auth_methods=(auth_methods_module)
|
39
|
-
@auth_class = CurrentSession::AuthMethod.new_auth_class(auth_methods_module)
|
40
|
-
end
|
41
|
-
|
42
|
-
def auth_methods(&block)
|
43
|
-
if block
|
44
|
-
@auth_methods = Module.new(&block)
|
45
|
-
@auth_class = CurrentSession::AuthMethod.new_auth_class(auth_methods)
|
46
|
-
@auth_class.user_class = user_class
|
47
|
-
else
|
48
|
-
@auth_methods
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
11
|
end
|
53
12
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CurrentSession
|
4
|
+
#
|
5
|
+
# configuration dsl
|
6
|
+
#
|
7
|
+
module Dsl
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
class_methods do
|
10
|
+
def session_methods=(session_method)
|
11
|
+
@session_methods = CurrentSession::SessionMethod.new_class(session_method)
|
12
|
+
end
|
13
|
+
|
14
|
+
def session_methods(&block)
|
15
|
+
if block
|
16
|
+
@session_methods = CurrentSession::SessionMethod.new_class(Module.new(&block))
|
17
|
+
else
|
18
|
+
@session_methods
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def auth_methods=(auth_method)
|
23
|
+
@auth_methods = CurrentSession::AuthMethod.new_class(auth_method)
|
24
|
+
end
|
25
|
+
|
26
|
+
def auth_methods(&block)
|
27
|
+
if block
|
28
|
+
@auth_methods = CurrentSession::AuthMethod.new_class(Module.new(&block))
|
29
|
+
else
|
30
|
+
@auth_methods
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -12,37 +12,18 @@ module CurrentSession
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def update(request)
|
15
|
-
|
16
|
-
repository.find { |user| self.current_user = user }
|
17
|
-
end
|
15
|
+
self.current_user = @session_methods.new(request).find
|
18
16
|
self
|
19
17
|
end
|
20
18
|
|
21
19
|
def create(request)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
session_repository(request).update_session_token(user)
|
26
|
-
end
|
20
|
+
self.current_user = @auth_methods.new(request).connect
|
21
|
+
@session_methods.new(request).create(current_user)
|
22
|
+
self
|
27
23
|
end
|
28
24
|
|
29
25
|
def destroy(request)
|
30
|
-
|
31
|
-
session_repository(request).try do |repository|
|
32
|
-
repository.destroy
|
33
|
-
repository.delete_session_token
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def session_repository(request)
|
40
|
-
@session_class.new(
|
41
|
-
request: request,
|
42
|
-
user_class: user_class,
|
43
|
-
session_token_class: session_token_class,
|
44
|
-
current_time: current_time(request)
|
45
|
-
)
|
26
|
+
@session_methods.new(request).destroy
|
46
27
|
end
|
47
28
|
end
|
48
29
|
end
|
@@ -2,45 +2,45 @@
|
|
2
2
|
|
3
3
|
module CurrentSession
|
4
4
|
#
|
5
|
-
#
|
5
|
+
# session Method
|
6
6
|
#
|
7
7
|
class SessionMethod
|
8
|
-
def self.
|
9
|
-
Class.new(
|
10
|
-
|
11
|
-
|
12
|
-
def initialize(current_time:, request:, user_class:, session_token_class:)
|
13
|
-
@current_time = current_time
|
14
|
-
@request = request
|
15
|
-
@user_class = user_class
|
16
|
-
@session_token_class = session_token_class
|
8
|
+
def self.new_class(methods)
|
9
|
+
Class.new(self) do
|
10
|
+
include methods
|
11
|
+
end
|
17
12
|
end
|
18
|
-
attr_reader :current_time, :request, :user_class, :session_token_class
|
19
13
|
|
20
|
-
def
|
21
|
-
|
14
|
+
def self.define(&block)
|
15
|
+
Module.new do
|
16
|
+
define_method(:find, &block)
|
17
|
+
define_method(:create) {}
|
18
|
+
define_method(:destroy) {}
|
19
|
+
end
|
22
20
|
end
|
23
21
|
|
24
|
-
def
|
25
|
-
@
|
22
|
+
def initialize(request)
|
23
|
+
@request = request
|
26
24
|
end
|
25
|
+
attr_reader :request
|
27
26
|
|
28
|
-
|
29
|
-
|
27
|
+
#
|
28
|
+
# @return User
|
29
|
+
#
|
30
|
+
def find
|
31
|
+
fail NotImplementedError, "You must implement #{self.class}##{__method__}"
|
30
32
|
end
|
31
33
|
|
32
|
-
def
|
33
|
-
|
34
|
+
def create(user)
|
35
|
+
fail NotImplementedError, "You must implement #{self.class}##{__method__}"
|
34
36
|
end
|
35
37
|
|
36
|
-
def
|
37
|
-
|
38
|
+
def destroy
|
39
|
+
fail NotImplementedError, "You must implement #{self.class}##{__method__}"
|
38
40
|
end
|
39
41
|
|
40
|
-
def
|
41
|
-
|
42
|
-
yield self
|
43
|
-
end
|
42
|
+
def new_session_token
|
43
|
+
SecureRandom.urlsafe_base64(128)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
data/lib/current_session.rb
CHANGED
@@ -9,12 +9,12 @@ require "active_support"
|
|
9
9
|
module CurrentSession
|
10
10
|
extend ActiveSupport::Autoload
|
11
11
|
autoload :Base
|
12
|
+
autoload :Dsl
|
12
13
|
autoload :Interface
|
13
14
|
autoload :AuthMethod
|
14
15
|
autoload :SessionMethod
|
15
|
-
autoload :SessionMethods
|
16
16
|
|
17
|
-
def self.key(
|
18
|
-
"session_#{
|
17
|
+
def self.key(namespace)
|
18
|
+
"session_#{namespace.name.underscore.parameterize(separator: "_")}_key"
|
19
19
|
end
|
20
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: current_session
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masa (Aileron inc)
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -148,12 +148,9 @@ files:
|
|
148
148
|
- lib/current_session.rb
|
149
149
|
- lib/current_session/auth_method.rb
|
150
150
|
- lib/current_session/base.rb
|
151
|
+
- lib/current_session/dsl.rb
|
151
152
|
- lib/current_session/interface.rb
|
152
153
|
- lib/current_session/session_method.rb
|
153
|
-
- lib/current_session/session_methods.rb
|
154
|
-
- lib/current_session/session_methods/active_record_session.rb
|
155
|
-
- lib/current_session/session_methods/env_session.rb
|
156
|
-
- lib/current_session/session_methods/uid_session.rb
|
157
154
|
- lib/current_session/version.rb
|
158
155
|
homepage: https://github.com/aileron-inc/current_session
|
159
156
|
licenses:
|
@@ -175,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
172
|
- !ruby/object:Gem::Version
|
176
173
|
version: '0'
|
177
174
|
requirements: []
|
178
|
-
rubygems_version: 3.
|
175
|
+
rubygems_version: 3.3.26
|
179
176
|
signing_key:
|
180
177
|
specification_version: 4
|
181
178
|
summary: Library for current_user using ActiveSupport::CurrentAttributes
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module CurrentSession
|
4
|
-
module SessionMethods
|
5
|
-
#
|
6
|
-
# Implementation of session tokens for DB management
|
7
|
-
#
|
8
|
-
module ActiveRecordSession
|
9
|
-
def find
|
10
|
-
session_token_class.find_by(value: session_token).try do |record|
|
11
|
-
update(record)
|
12
|
-
yield record.user
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def create(user)
|
17
|
-
session_token_class.create(user_id: user.id, value: new_session_token) do |record|
|
18
|
-
update(record)
|
19
|
-
end.value
|
20
|
-
end
|
21
|
-
|
22
|
-
def update(token)
|
23
|
-
token.update(
|
24
|
-
last_request_at: current_time,
|
25
|
-
last_request_ip: request.remote_ip,
|
26
|
-
last_request_user_agent: request.user_agent
|
27
|
-
)
|
28
|
-
end
|
29
|
-
|
30
|
-
def destroy
|
31
|
-
session_token_class.find_by(value: session_token)&.destroy
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module CurrentSession
|
4
|
-
module SessionMethods
|
5
|
-
#
|
6
|
-
# repository to return the user specified by the environment variable
|
7
|
-
#
|
8
|
-
module EnvSession
|
9
|
-
# rubocop:disable Metrics/MethodLength
|
10
|
-
def self.build(current_user_id)
|
11
|
-
Module.new do
|
12
|
-
define_method(:current_user) { user_class.find(current_user_id) }
|
13
|
-
|
14
|
-
def try
|
15
|
-
yield self
|
16
|
-
end
|
17
|
-
|
18
|
-
def find
|
19
|
-
yield current_user
|
20
|
-
end
|
21
|
-
|
22
|
-
def create(_)
|
23
|
-
end
|
24
|
-
|
25
|
-
def destroy
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
# rubocop:enable Metrics/MethodLength
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module CurrentSession
|
4
|
-
module SessionMethods
|
5
|
-
#
|
6
|
-
# Implementation of using UIDs as session tokens
|
7
|
-
#
|
8
|
-
module UidSession
|
9
|
-
def find(&block)
|
10
|
-
user_class.find_by(uid: session_token).try(&block)
|
11
|
-
end
|
12
|
-
|
13
|
-
def create(user)
|
14
|
-
user.uid
|
15
|
-
end
|
16
|
-
|
17
|
-
def destroy
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
#
|
4
|
-
# Reference implementation of session_methods
|
5
|
-
#
|
6
|
-
module CurrentSession
|
7
|
-
module SessionMethods
|
8
|
-
extend ActiveSupport::Autoload
|
9
|
-
autoload :UidSession
|
10
|
-
autoload :EnvSession
|
11
|
-
autoload :ActiveRecordSession
|
12
|
-
end
|
13
|
-
end
|