isomorfeus-transport 2.2.11 → 2.3.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 +0 -1
- data/lib/isomorfeus/transport/config.rb +0 -62
- data/lib/isomorfeus/transport/handler/authentication_handler.rb +2 -2
- data/lib/isomorfeus/transport/rack_middleware.rb +13 -10
- data/lib/isomorfeus/transport/server_socket_processor.rb +24 -15
- data/lib/isomorfeus/transport/version.rb +1 -1
- data/lib/isomorfeus/transport.rb +10 -0
- data/lib/isomorfeus-transport.rb +0 -2
- metadata +12 -28
- data/lib/isomorfeus/transport/hamster_session_store.rb +0 -96
- data/lib/lucid_authentication/mixin.rb +0 -123
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17d091f9644e919161c0c8cbe7c373e5087d16d34a8978ebe704904da0a060ca
|
4
|
+
data.tar.gz: 7aa732e7e24caebd2945caf32ecada3ecfc56b5f01a00ea498fc025f31a6838e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ac6e0d72a4c8a955ba5f5d85ce83be579d1c753752c8f420f0859907fd8d112d2ae5b630e72756f740936a9469990a5cd84048157143304506aef2e9348bb7e
|
7
|
+
data.tar.gz: 55d3d7e6d303bde3df2e573f2e0001536a740e5644fa5a0b8ebeb14c88fffb78cee84b1a446fb38bf6f54f7f467c1e581c90800232ee91990942ade758a20832
|
data/README.md
CHANGED
@@ -23,5 +23,4 @@ Server only:
|
|
23
23
|
|
24
24
|
## Usage
|
25
25
|
|
26
|
-
- [Authentication and Current User](https://github.com/isomorfeus/isomorfeus-project/blob/master/isomorfeus-transport/docs/authentication.md)
|
27
26
|
- [Channels (PubSub)](https://github.com/isomorfeus/isomorfeus-project/blob/master/isomorfeus-transport/docs/channels.md)
|
@@ -43,28 +43,6 @@ module Isomorfeus
|
|
43
43
|
def add_transport_init_class_name(init_class_name)
|
44
44
|
transport_init_class_names << init_class_name
|
45
45
|
end
|
46
|
-
|
47
|
-
def current_user
|
48
|
-
@current_user ||= init_current_user
|
49
|
-
end
|
50
|
-
|
51
|
-
def init_current_user
|
52
|
-
if Isomorfeus.current_user_sid
|
53
|
-
Isomorfeus.instance_from_sid(Isomorfeus.current_user_sid)
|
54
|
-
else
|
55
|
-
Anonymous.new
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def set_current_user(user)
|
60
|
-
if user
|
61
|
-
@current_user = user
|
62
|
-
Isomorfeus.current_user_sid = user.sid
|
63
|
-
else
|
64
|
-
@current_user = Anonymous.new
|
65
|
-
Isomorfeus.current_user_sid = nil
|
66
|
-
end
|
67
|
-
end
|
68
46
|
end
|
69
47
|
else
|
70
48
|
class << self
|
@@ -73,7 +51,6 @@ module Isomorfeus
|
|
73
51
|
attr_accessor :api_websocket_path
|
74
52
|
attr_accessor :api_logout_path
|
75
53
|
attr_accessor :cookie_eater_path
|
76
|
-
attr_reader :session_store
|
77
54
|
|
78
55
|
def valid_channel_class_name?(class_name)
|
79
56
|
valid_channel_class_names.include?(class_name)
|
@@ -131,48 +108,9 @@ module Isomorfeus
|
|
131
108
|
cached_handler_classes[class_name] = "::#{class_name}".constantize
|
132
109
|
end
|
133
110
|
|
134
|
-
def valid_user_class_names
|
135
|
-
@valid_user_class_names ||= Set.new
|
136
|
-
end
|
137
|
-
|
138
|
-
def valid_user_class_name?(class_name)
|
139
|
-
valid_user_class_names.include?(class_name)
|
140
|
-
end
|
141
|
-
|
142
|
-
def add_valid_user_class(klass)
|
143
|
-
valid_user_class_names << raw_class_name(klass)
|
144
|
-
end
|
145
|
-
|
146
|
-
def cached_user_classes
|
147
|
-
@cached_user_classes ||= {}
|
148
|
-
end
|
149
|
-
|
150
|
-
def cached_user_class(class_name)
|
151
|
-
return "::#{class_name}".constantize if Isomorfeus.development?
|
152
|
-
return cached_user_classes[class_name] if cached_user_classes.key?(class_name)
|
153
|
-
cached_user_classes[class_name] = "::#{class_name}".constantize
|
154
|
-
end
|
155
|
-
|
156
|
-
def current_user
|
157
|
-
Thread.current[:isomorfeus_user] ||= Anonymous.new
|
158
|
-
end
|
159
|
-
|
160
111
|
def pub_sub_client
|
161
112
|
Thread.current[:isomorfeus_pub_sub_client]
|
162
113
|
end
|
163
|
-
|
164
|
-
def session_store
|
165
|
-
@session_store ||= @session_store_init.call
|
166
|
-
end
|
167
|
-
|
168
|
-
def session_store_init(&block)
|
169
|
-
@session_store_init = block
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
self.session_store_init do
|
174
|
-
store_path = File.expand_path(File.join(Isomorfeus.root, 'storage', Isomorfeus.env, 'session_store'))
|
175
|
-
Isomorfeus::Transport::HamsterSessionStore.new(store_path)
|
176
114
|
end
|
177
115
|
end
|
178
116
|
|
@@ -34,14 +34,14 @@ module Isomorfeus
|
|
34
34
|
session_cookie = "session=#{session_id}; SameSite=Strict; HttpOnly; Path=/; Max-Age=2592000#{'; Secure' if Isomorfeus.production?}"
|
35
35
|
session_cookie_accessor = SecureRandom.uuid
|
36
36
|
Isomorfeus.pub_sub_client.instance_variable_set(:@isomorfeus_authentication_tries, nil)
|
37
|
-
Isomorfeus.
|
37
|
+
Isomorfeus.session_class.add(session_id: session_id, cookie: session_cookie, user: user, accessor: session_cookie_accessor)
|
38
38
|
response_agent.agent_result = { success: 'ok', data: user.to_transport, session_cookie_accessor: session_cookie_accessor }
|
39
39
|
end
|
40
40
|
end
|
41
41
|
elsif login_or_ssr_login == 'ssr_login'
|
42
42
|
response_agent.agent_result = { error: 'Authentication failed' }
|
43
43
|
session_id = response_agent.request['ssr_login']
|
44
|
-
user = Isomorfeus.
|
44
|
+
user = Isomorfeus.session_class.get_user(session_id: session_id)
|
45
45
|
if user
|
46
46
|
Isomorfeus.pub_sub_client.instance_variable_set(:@isomorfeus_authentication_tries, nil)
|
47
47
|
response_agent.agent_result = { success: 'ok', data: user.to_transport }
|
@@ -16,23 +16,26 @@ module Isomorfeus
|
|
16
16
|
cookie = cookies.detect { |c| c.start_with?('session=') }
|
17
17
|
if cookie
|
18
18
|
session_id = cookie[8..-1]
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
if !session_id.nil? && !session_id.empty?
|
20
|
+
user = Isomorfeus.session_class&.get_user(session_id: session_id)
|
21
|
+
return [user, session_id] unless user.nil?
|
22
|
+
end
|
22
23
|
end
|
23
24
|
end
|
25
|
+
[Anonymous.new, nil]
|
24
26
|
end
|
25
27
|
|
26
28
|
def call(env)
|
27
|
-
|
29
|
+
case env['PATH_INFO']
|
30
|
+
when Isomorfeus.api_websocket_path
|
28
31
|
if env['rack.upgrade?'] == :websocket
|
29
|
-
user,
|
30
|
-
env['rack.upgrade'] = Isomorfeus::Transport::ServerSocketProcessor.new(user)
|
32
|
+
user, session_id = user_from_env(env)
|
33
|
+
env['rack.upgrade'] = Isomorfeus::Transport::ServerSocketProcessor.new(user, session_id)
|
31
34
|
end
|
32
35
|
WS_RESPONSE
|
33
|
-
|
36
|
+
when Isomorfeus.cookie_eater_path
|
34
37
|
cookie_accessor, new_path = env['QUERY_STRING'].split('=')
|
35
|
-
cookie = Isomorfeus.
|
38
|
+
cookie = Isomorfeus.session_class&.take_cookie(accessor: cookie_accessor)
|
36
39
|
if new_path.start_with?('/')
|
37
40
|
if cookie
|
38
41
|
[302, { 'Location' => new_path, 'Set-Cookie' => cookie }, ["Cookie eaten!"]]
|
@@ -42,11 +45,11 @@ module Isomorfeus
|
|
42
45
|
else
|
43
46
|
[404, {}, ["Must specify relative path!"]]
|
44
47
|
end
|
45
|
-
|
48
|
+
when Isomorfeus.api_logout_path
|
46
49
|
user, session_id = user_from_env(env)
|
47
50
|
if user
|
48
51
|
begin
|
49
|
-
Isomorfeus.
|
52
|
+
Isomorfeus.session_class&.remove(session_id: session_id)
|
50
53
|
cookie = "session=#{session_id}; SameSite=Strict; HttpOnly; Path=/; expires=Thu, 01 Jan 1970 00:00:00 UTC#{'; Secure' if Isomorfeus.production?}"
|
51
54
|
return [302, { 'Location' => '/', 'Set-Cookie' => cookie }, ["Logged out!"]]
|
52
55
|
ensure
|
@@ -3,8 +3,10 @@ module Isomorfeus
|
|
3
3
|
class ServerSocketProcessor
|
4
4
|
include Isomorfeus::Transport::ServerProcessor
|
5
5
|
|
6
|
-
def initialize(user)
|
6
|
+
def initialize(user, session_id)
|
7
7
|
@user = user
|
8
|
+
@session_id = session_id
|
9
|
+
@atime = Time.now
|
8
10
|
end
|
9
11
|
|
10
12
|
def on_message(client, data)
|
@@ -19,19 +21,21 @@ module Isomorfeus
|
|
19
21
|
Isomorfeus.zeitwerk_lock.acquire_read_lock
|
20
22
|
end
|
21
23
|
request_hash = Oj.load(data, mode: :strict)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
24
|
+
Thread.current[:isomorfeus_user] = user
|
25
|
+
unless request_hash.key?(:iso_ping)
|
26
|
+
handler_instance_cache = {}
|
27
|
+
response_agent_array = []
|
28
|
+
Thread.current[:isomorfeus_pub_sub_client] = client
|
29
|
+
process_request(request_hash, handler_instance_cache, response_agent_array)
|
30
|
+
handler_instance_cache.each_value do |handler|
|
31
|
+
handler.resolve if handler.resolving?
|
32
|
+
end
|
33
|
+
result = {}
|
34
|
+
response_agent_array.each do |response_agent|
|
35
|
+
result.deep_merge!(response_agent.result)
|
36
|
+
end
|
37
|
+
client.write Oj.dump(result, mode: :strict) unless result.empty?
|
33
38
|
end
|
34
|
-
client.write Oj.dump(result, mode: :strict) unless result.empty?
|
35
39
|
ensure
|
36
40
|
Thread.current[:isomorfeus_user] = nil
|
37
41
|
Thread.current[:isomorfeus_pub_sub_client] = nil
|
@@ -50,8 +54,13 @@ module Isomorfeus
|
|
50
54
|
# nothing for now
|
51
55
|
end
|
52
56
|
|
53
|
-
def user
|
54
|
-
|
57
|
+
def user
|
58
|
+
t = Time.now
|
59
|
+
if @session_id && (t - @atime) > 600
|
60
|
+
Isomorfeus.session_class&.touch(session_id: @session_id)
|
61
|
+
@atime = t
|
62
|
+
end
|
63
|
+
@user
|
55
64
|
end
|
56
65
|
end
|
57
66
|
end
|
data/lib/isomorfeus/transport.rb
CHANGED
@@ -2,6 +2,8 @@ module Isomorfeus
|
|
2
2
|
module Transport
|
3
3
|
class << self
|
4
4
|
if RUBY_ENGINE == 'opal'
|
5
|
+
PING = `JSON.stringify({iso_ping: true})`
|
6
|
+
|
5
7
|
attr_accessor :socket
|
6
8
|
|
7
9
|
def init
|
@@ -57,10 +59,18 @@ module Isomorfeus
|
|
57
59
|
open_promise.then { promise_send_request(request) } if agent && !agent.sent
|
58
60
|
end
|
59
61
|
open_promise.then { promise.resolve(true) }
|
62
|
+
keep_session_alive if on_browser?
|
60
63
|
end
|
61
64
|
promise
|
62
65
|
end
|
63
66
|
|
67
|
+
def keep_session_alive
|
68
|
+
after 480000 do
|
69
|
+
@socket.send(PING)
|
70
|
+
keep_session_alive
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
64
74
|
def disconnect
|
65
75
|
@socket.close if @socket
|
66
76
|
@socket = nil
|
data/lib/isomorfeus-transport.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'isomorfeus-policy'
|
2
|
-
require 'lucid_authentication/mixin'
|
3
2
|
if RUBY_ENGINE == 'opal'
|
4
3
|
require 'json'
|
5
4
|
require 'isomorfeus/transport/version'
|
@@ -33,7 +32,6 @@ else
|
|
33
32
|
require 'active_support'
|
34
33
|
require 'isomorfeus-asset-manager'
|
35
34
|
require 'isomorfeus-hamster'
|
36
|
-
require 'isomorfeus/transport/hamster_session_store'
|
37
35
|
opal_path = Gem::Specification.find_by_name('opal').full_gem_path
|
38
36
|
promise_path = File.join(opal_path, 'stdlib', 'promise.rb')
|
39
37
|
require promise_path
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: isomorfeus-transport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Biedermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -100,56 +100,42 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.14.
|
103
|
+
version: 0.14.21
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 0.14.
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: isomorfeus-hamster
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "~>"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: 0.6.6
|
118
|
-
type: :runtime
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: 0.6.6
|
110
|
+
version: 0.14.21
|
125
111
|
- !ruby/object:Gem::Dependency
|
126
112
|
name: isomorfeus-preact
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
128
114
|
requirements:
|
129
115
|
- - "~>"
|
130
116
|
- !ruby/object:Gem::Version
|
131
|
-
version: 10.6.
|
117
|
+
version: 10.6.60
|
132
118
|
type: :runtime
|
133
119
|
prerelease: false
|
134
120
|
version_requirements: !ruby/object:Gem::Requirement
|
135
121
|
requirements:
|
136
122
|
- - "~>"
|
137
123
|
- !ruby/object:Gem::Version
|
138
|
-
version: 10.6.
|
124
|
+
version: 10.6.60
|
139
125
|
- !ruby/object:Gem::Dependency
|
140
126
|
name: isomorfeus-policy
|
141
127
|
requirement: !ruby/object:Gem::Requirement
|
142
128
|
requirements:
|
143
129
|
- - '='
|
144
130
|
- !ruby/object:Gem::Version
|
145
|
-
version: 2.
|
131
|
+
version: 2.3.0
|
146
132
|
type: :runtime
|
147
133
|
prerelease: false
|
148
134
|
version_requirements: !ruby/object:Gem::Requirement
|
149
135
|
requirements:
|
150
136
|
- - '='
|
151
137
|
- !ruby/object:Gem::Version
|
152
|
-
version: 2.
|
138
|
+
version: 2.3.0
|
153
139
|
- !ruby/object:Gem::Dependency
|
154
140
|
name: isomorfeus-redux
|
155
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -170,14 +156,14 @@ dependencies:
|
|
170
156
|
requirements:
|
171
157
|
- - "~>"
|
172
158
|
- !ruby/object:Gem::Version
|
173
|
-
version: 0.5.
|
159
|
+
version: 0.5.3
|
174
160
|
type: :runtime
|
175
161
|
prerelease: false
|
176
162
|
version_requirements: !ruby/object:Gem::Requirement
|
177
163
|
requirements:
|
178
164
|
- - "~>"
|
179
165
|
- !ruby/object:Gem::Version
|
180
|
-
version: 0.5.
|
166
|
+
version: 0.5.3
|
181
167
|
- !ruby/object:Gem::Dependency
|
182
168
|
name: rack
|
183
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -226,14 +212,14 @@ dependencies:
|
|
226
212
|
requirements:
|
227
213
|
- - '='
|
228
214
|
- !ruby/object:Gem::Version
|
229
|
-
version: 2.
|
215
|
+
version: 2.3.0
|
230
216
|
type: :development
|
231
217
|
prerelease: false
|
232
218
|
version_requirements: !ruby/object:Gem::Requirement
|
233
219
|
requirements:
|
234
220
|
- - '='
|
235
221
|
- !ruby/object:Gem::Version
|
236
|
-
version: 2.
|
222
|
+
version: 2.3.0
|
237
223
|
- !ruby/object:Gem::Dependency
|
238
224
|
name: rake
|
239
225
|
requirement: !ruby/object:Gem::Requirement
|
@@ -275,7 +261,6 @@ files:
|
|
275
261
|
- lib/isomorfeus/transport/client_processor.rb
|
276
262
|
- lib/isomorfeus/transport/compressor_rack.rb
|
277
263
|
- lib/isomorfeus/transport/config.rb
|
278
|
-
- lib/isomorfeus/transport/hamster_session_store.rb
|
279
264
|
- lib/isomorfeus/transport/handler/authentication_handler.rb
|
280
265
|
- lib/isomorfeus/transport/imports.rb
|
281
266
|
- lib/isomorfeus/transport/middlewares.rb
|
@@ -287,7 +272,6 @@ files:
|
|
287
272
|
- lib/isomorfeus/transport/ssr_login.rb
|
288
273
|
- lib/isomorfeus/transport/version.rb
|
289
274
|
- lib/isomorfeus/transport/websocket_client.rb
|
290
|
-
- lib/lucid_authentication/mixin.rb
|
291
275
|
- lib/lucid_channel/base.rb
|
292
276
|
- lib/lucid_channel/mixin.rb
|
293
277
|
- lib/lucid_handler/base.rb
|
@@ -1,96 +0,0 @@
|
|
1
|
-
module Isomorfeus
|
2
|
-
module Transport
|
3
|
-
class HamsterSessionStore
|
4
|
-
class << self
|
5
|
-
def environment
|
6
|
-
@environment
|
7
|
-
end
|
8
|
-
|
9
|
-
def environment=(env)
|
10
|
-
@environment = env
|
11
|
-
end
|
12
|
-
|
13
|
-
def ref
|
14
|
-
@ref ||= 0
|
15
|
-
end
|
16
|
-
|
17
|
-
def ref=(val)
|
18
|
-
@ref = val
|
19
|
-
end
|
20
|
-
|
21
|
-
def refa
|
22
|
-
self.ref += 1
|
23
|
-
end
|
24
|
-
|
25
|
-
def refs
|
26
|
-
self.ref -= 1 if self.ref > 0
|
27
|
-
end
|
28
|
-
|
29
|
-
def finalize(cls)
|
30
|
-
proc do
|
31
|
-
cls.refs
|
32
|
-
if cls.ref == 0
|
33
|
-
cls.environment.close rescue nil
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def initialize(cookie_hamster_path)
|
40
|
-
@cookie_hamster_path = cookie_hamster_path
|
41
|
-
open_environment
|
42
|
-
@db = self.class.environment.database('cookies', create: true)
|
43
|
-
ObjectSpace.define_finalizer(self, self.class.finalize(self.class))
|
44
|
-
end
|
45
|
-
|
46
|
-
def add(session_id:, cookie:, user:, accessor:)
|
47
|
-
@db.env.transaction do
|
48
|
-
@db.put(session_id, Oj.dump([user.class.to_s, user.key], mode: :strict))
|
49
|
-
@db.put(accessor, cookie)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def take_cookie(accessor:)
|
54
|
-
@db.env.transaction do
|
55
|
-
cookie = @db.get(accessor)
|
56
|
-
if cookie
|
57
|
-
session_info = cookie.split('; ').first
|
58
|
-
session_id = session_info.split('=').last.strip
|
59
|
-
@db.put("eaten_#{accessor}", session_id)
|
60
|
-
@db.delete(accessor)
|
61
|
-
else
|
62
|
-
# asked for the same cookie a second time
|
63
|
-
# can probably only be due to session hijacking
|
64
|
-
# so delete all sessions associated with that accessor
|
65
|
-
session_id = @db.get("eaten_#{accessor}")
|
66
|
-
@db.delete(session_id) if session_id
|
67
|
-
end
|
68
|
-
cookie
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def get_user(session_id:)
|
73
|
-
json = @db.get(session_id)
|
74
|
-
if json
|
75
|
-
user_info = Oj.load(json, mode: :strict)
|
76
|
-
user_info[0].constantize.load(key: user_info[1]) if user_info
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def remove(session_id:)
|
81
|
-
@db.env.transaction do
|
82
|
-
@db.delete(session_id)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
private
|
87
|
-
|
88
|
-
def open_environment
|
89
|
-
return self.class.refa if self.class.environment
|
90
|
-
FileUtils.mkdir_p(@cookie_hamster_path) unless Dir.exist?(@cookie_hamster_path)
|
91
|
-
self.class.environment = Isomorfeus::Hamster.new(@cookie_hamster_path)
|
92
|
-
self.class.refa
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
@@ -1,123 +0,0 @@
|
|
1
|
-
module LucidAuthentication
|
2
|
-
module Mixin
|
3
|
-
def anonymous?
|
4
|
-
self.class == Anonymous
|
5
|
-
end
|
6
|
-
|
7
|
-
if RUBY_ENGINE == 'opal'
|
8
|
-
def self.included(base)
|
9
|
-
base.instance_exec do
|
10
|
-
def execute_login(&block)
|
11
|
-
end
|
12
|
-
|
13
|
-
def promise_login(user: nil, pass: nil, scheme: :isomorfeus, &block)
|
14
|
-
send("promise_authentication_with_#{scheme}", user: user, pass: pass, &block)
|
15
|
-
end
|
16
|
-
|
17
|
-
def promise_authentication_with_isomorfeus(user: nil, pass: nil, &block)
|
18
|
-
if Isomorfeus.production?
|
19
|
-
Isomorfeus.raise_error(message: "Connection not secure, can't login!") unless Isomorfeus::Transport.socket.url.start_with?('wss:')
|
20
|
-
else
|
21
|
-
`console.warn("Connection not secure, ensure a secure connection in production, otherwise login will fail!")` unless Isomorfeus::Transport.socket.url.start_with?('wss:')
|
22
|
-
end
|
23
|
-
Isomorfeus::Transport.promise_send_path('Isomorfeus::Transport::Handler::AuthenticationHandler', 'login', self.name, user, pass).then do |agent|
|
24
|
-
if agent.processed
|
25
|
-
agent.result
|
26
|
-
else
|
27
|
-
agent.processed = true
|
28
|
-
if agent.response.key?(:success)
|
29
|
-
Isomorfeus.store.dispatch(type: 'DATA_LOAD', data: agent.response[:data])
|
30
|
-
class_name = agent.response[:data].keys.first
|
31
|
-
key = agent.response[:data][class_name].keys.first
|
32
|
-
logged_in_user = Isomorfeus.cached_data_class(class_name).new(key: key)
|
33
|
-
cookie_accessor = agent.response[:session_cookie_accessor]
|
34
|
-
begin
|
35
|
-
target = if block_given?
|
36
|
-
block.call(logged_in_user)
|
37
|
-
else
|
38
|
-
`window.location.pathname`
|
39
|
-
end
|
40
|
-
unless target.class == String && target.start_with?('/')
|
41
|
-
Isomorfeus.raise_error(message: "A path must be returned as string starting with '/', returned was #{target}!")
|
42
|
-
end
|
43
|
-
rescue
|
44
|
-
target = `window.location.pathname`
|
45
|
-
end
|
46
|
-
cookie_query = "#{Isomorfeus.cookie_eater_path}?#{cookie_accessor}=#{target}"
|
47
|
-
`window.location = cookie_query` # doing page load and redirect
|
48
|
-
nil
|
49
|
-
else
|
50
|
-
Isomorfeus.raise_error(message: "Login failed with '#{agent.response[:error]}'!") # triggers .fail
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def promise_logout(scheme: :isomorfeus)
|
59
|
-
send("promise_deauthentication_with_#{scheme}")
|
60
|
-
end
|
61
|
-
|
62
|
-
def promise_deauthentication_with_isomorfeus
|
63
|
-
cookie = `document.cookie`
|
64
|
-
p = Promise.new
|
65
|
-
begin
|
66
|
-
logout_query = Isomorfeus.api_logout_path
|
67
|
-
`window.location = logout_query`
|
68
|
-
rescue
|
69
|
-
p.reject
|
70
|
-
end
|
71
|
-
end
|
72
|
-
else
|
73
|
-
def self.included(base)
|
74
|
-
Isomorfeus.add_valid_user_class(base)
|
75
|
-
|
76
|
-
base.instance_exec do
|
77
|
-
def execute_login(&block)
|
78
|
-
@execute_login_block = block
|
79
|
-
end
|
80
|
-
|
81
|
-
def promise_login(user: nil, pass: nil, scheme: :isomorfeus, &block)
|
82
|
-
send("promise_authentication_with_#{scheme}", user: user, pass: pass, &block)
|
83
|
-
end
|
84
|
-
|
85
|
-
def promise_authentication_with_isomorfeus(user: nil, pass: nil, &block)
|
86
|
-
promise_or_user = @execute_login_block.call(user: user, pass: pass)
|
87
|
-
if promise_or_user.class == Promise
|
88
|
-
if block_given?
|
89
|
-
promise_or_user.then do |user|
|
90
|
-
block.call(user)
|
91
|
-
user
|
92
|
-
end
|
93
|
-
else
|
94
|
-
promise_or_user
|
95
|
-
end
|
96
|
-
else
|
97
|
-
block.call(user) if block_given?
|
98
|
-
Promise.new.resolve(promise_or_user)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
def encrypt_password(password, password_confirmation)
|
105
|
-
raise "Password and confirmation don't match!" unless password == password_confirmation
|
106
|
-
BCrypt::Password.create(password).to_s
|
107
|
-
end
|
108
|
-
|
109
|
-
def passwords_match?(encrypted_password, given_password)
|
110
|
-
bcrypt_pass = BCrypt::Password.new(encrypted_password)
|
111
|
-
bcrypt_pass == given_password
|
112
|
-
end
|
113
|
-
|
114
|
-
def promise_logout(scheme: :isomorfeus)
|
115
|
-
send("promise_deauthentication_with_#{scheme}")
|
116
|
-
end
|
117
|
-
|
118
|
-
def promise_deauthentication_with_isomorfeus
|
119
|
-
Promise.new.resolve(true)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|