isomorfeus-transport 2.0.0.rc9 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8201ea5030ef2db3bb57a590ab9a76b37305634b8a21b9aab6b5dc2397739f8
4
- data.tar.gz: a0d350ad0f97a085a257727b3897848611dba3093fb5554ff150af6deb15322f
3
+ metadata.gz: '014479eeaec2d02e863f3e71fad9dd13baa99b99103cd46a922929aba1a7311c'
4
+ data.tar.gz: 4b88a670a325f1c834bc35259ace1f396cdc9611442f2f3f10cc3c00227616f5
5
5
  SHA512:
6
- metadata.gz: 96ee8d0f258ce35e106310d11924bc87be91b6ed77c121425c1f90b2b3393825ae0973665d27c1b668b98681a31d80e4bc6d3f78394e6f5f088875257a2f5a1f
7
- data.tar.gz: e6918a388257422d7dcc9799bc3217d138ee221febb26241318a1dffdbf8dd74178a75c1b74f2f7637932145fc95686ef7d15a57d47f7f744a4cb40d794d837e
6
+ metadata.gz: 6187c2351668a657d6ddf6e14e881b1dd509b13d0d216174e0f483c611550f3c1f1b933b7b9881bf1ffec2d65a8247848062dd4d2769f220f234d6a97697196f
7
+ data.tar.gz: d7a94c2543aaf0e56fad460f8d52142b669b8d44530368da9cfbd11a63f40244c70b0ad1d281d3e444ff9ba9739668d1e5454ccecd70167298839b84e5608bde
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Transport and PubSub for Isomorfeus.
4
4
 
5
5
  ### Community and Support
6
- At the [Isomorfeus Framework Project](http://isomorfeus.com)
6
+ At the [Isomorfeus Framework Project](http://isomorfeus.com)
7
7
 
8
8
  ## Installation
9
9
  isomorfeus-transport is usually installed with the installer.
@@ -23,5 +23,5 @@ Server only:
23
23
 
24
24
  ## Usage
25
25
 
26
- - [Authentication and Current User](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-transport/docs/authentication.md)
27
- - [Channels (PubSub)](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-transport/docs/channels.md)
26
+ - [Authentication and Current User](https://github.com/isomorfeus/isomorfeus-project/blob/master/isomorfeus-transport/docs/authentication.md)
27
+ - [Channels (PubSub)](https://github.com/isomorfeus/isomorfeus-project/blob/master/isomorfeus-transport/docs/channels.md)
@@ -30,6 +30,7 @@ module Isomorfeus
30
30
  add_client_option(:api_websocket_host)
31
31
  add_client_option(:api_websocket_port)
32
32
  add_client_option(:api_websocket_path)
33
+ add_client_option(:api_logout_path)
33
34
  add_client_option(:cookie_eater_path)
34
35
  add_client_option(:transport_init_class_names, [])
35
36
 
@@ -69,6 +70,7 @@ module Isomorfeus
69
70
  attr_accessor :api_websocket_host
70
71
  attr_accessor :api_websocket_port
71
72
  attr_accessor :api_websocket_path
73
+ attr_accessor :api_logout_path
72
74
  attr_accessor :cookie_eater_path
73
75
  attr_reader :session_store
74
76
 
@@ -168,8 +170,8 @@ module Isomorfeus
168
170
  end
169
171
 
170
172
  self.session_store_init do
171
- store_path = File.expand_path(File.join(Isomorfeus.root, 'data', Isomorfeus.env), 'session_store')
172
- Isomorfeus::Transport::HamsterSessionStore.new(store_path) # dont use this one, but we keep it here to have at least something
173
+ store_path = File.expand_path(File.join(Isomorfeus.root, 'data', Isomorfeus.env, 'session_store'))
174
+ Isomorfeus::Transport::HamsterSessionStore.new(store_path)
173
175
  end
174
176
  end
175
177
 
@@ -177,6 +179,6 @@ module Isomorfeus
177
179
  self.api_websocket_host = 'localhost'
178
180
  self.api_websocket_port = '3000'
179
181
  self.api_websocket_path = '/isomorfeus/api/websocket'
180
-
181
- self.cookie_eater_path = '/isomorfeus/cookie/eat'
182
+ self.api_logout_path = '/isomorfeus/api/logout'
183
+ self.cookie_eater_path = '/isomorfeus/cookie/eat'
182
184
  end
@@ -6,8 +6,8 @@ module Isomorfeus
6
6
 
7
7
  on_request do |response_agent|
8
8
  # promise_send_path('Isomorfeus::Transport::Handler::AuthenticationHandler', 'login', user_class_name, user_identifier, user_password)
9
- response_agent.request.each_key do |login_or_logout|
10
- if login_or_logout == 'login'
9
+ response_agent.request.each_key do |login_or_ssr_login|
10
+ if login_or_ssr_login == 'login'
11
11
  response_agent.agent_result = { error: 'Authentication failed' }
12
12
  tries = pub_sub_client.instance_variable_get(:@isomorfeus_authentication_tries)
13
13
  tries = 0 unless tries
@@ -33,34 +33,19 @@ module Isomorfeus
33
33
  session_id = SecureRandom.uuid
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
- Isomorfeus.pub_sub_client.instance_variable_set(:@isomorfeus_user, user)
37
36
  Isomorfeus.pub_sub_client.instance_variable_set(:@isomorfeus_authentication_tries, nil)
38
- Isomorfeus.pub_sub_client.instance_variable_set(:@isomorfeus_session_cookie, session_cookie)
39
37
  Isomorfeus.session_store.add(session_id: session_id, cookie: session_cookie, user: user, accessor: session_cookie_accessor)
40
38
  response_agent.agent_result = { success: 'ok', data: user.to_transport, session_cookie_accessor: session_cookie_accessor }
41
39
  end
42
40
  end
43
- elsif login_or_logout == 'ssr_login'
41
+ elsif login_or_ssr_login == 'ssr_login'
44
42
  response_agent.agent_result = { error: 'Authentication failed' }
45
43
  session_id = response_agent.request['ssr_login']
46
44
  user = Isomorfeus.session_store.get_user(session_id: session_id)
47
45
  if user
48
- Isomorfeus.pub_sub_client.instance_variable_set(:@isomorfeus_user, user)
49
46
  Isomorfeus.pub_sub_client.instance_variable_set(:@isomorfeus_authentication_tries, nil)
50
- Isomorfeus.pub_sub_client.instance_variable_set(:@isomorfeus_session_cookie, nil)
51
47
  response_agent.agent_result = { success: 'ok', data: user.to_transport }
52
48
  end
53
- elsif login_or_logout == 'logout'
54
- begin
55
- # bogus
56
- session_cookie = nil
57
- ensure
58
- Isomorfeus.pub_sub_client.instance_variable_set(:@isomorfeus_user, nil)
59
- Isomorfeus.pub_sub_client.instance_variable_set(:@isomorfeus_authentication_tries, nil)
60
- Isomorfeus.pub_sub_client.instance_variable_set(:@isomorfeus_session_cookie, nil)
61
- Isomorfeus.session_store.remove(cookie: session_cookie)
62
- response_agent.agent_result = { success: 'ok' }
63
- end
64
49
  end
65
50
  end
66
51
  end
@@ -9,10 +9,24 @@ module Isomorfeus
9
9
  @app = app
10
10
  end
11
11
 
12
+ def user_from_env(env)
13
+ cookies = env['HTTP_COOKIE']
14
+ if cookies
15
+ cookies = cookies.split('; ')
16
+ cookie = cookies.detect { |c| c.start_with?('session=') }
17
+ if cookie
18
+ session_id = cookie[8..-1]
19
+ user = Isomorfeus.session_store.get_user(session_id: session_id)
20
+ [user, session_id]
21
+ end
22
+ end
23
+ end
24
+
12
25
  def call(env)
13
26
  if env['PATH_INFO'] == Isomorfeus.api_websocket_path
14
27
  if env['rack.upgrade?'] == :websocket
15
- env['rack.upgrade'] = Isomorfeus::Transport::ServerSocketProcessor.new
28
+ user, _session_id = user_from_env(env)
29
+ env['rack.upgrade'] = Isomorfeus::Transport::ServerSocketProcessor.new(user)
16
30
  end
17
31
  WS_RESPONSE
18
32
  elsif env['PATH_INFO'] == Isomorfeus.cookie_eater_path
@@ -27,20 +41,25 @@ module Isomorfeus
27
41
  else
28
42
  [404, {}, ["Must specify relative path!"]]
29
43
  end
30
- else
31
- cookies = env['HTTP_COOKIE']
32
- if cookies
33
- cookies = cookies.split('; ')
34
- cookie = cookies.detect { |c| c.start_with?('session=') }
35
- if cookie
36
- session_id = cookie[8..-1]
37
- user = Isomorfeus.session_store.get_user(session_id: session_id)
38
- if user
39
- Thread.current[:isomorfeus_user] = user
40
- Thread.current[:isomorfeus_session_id] = session_id
41
- end
44
+ elsif env['PATH_INFO'] == Isomorfeus.api_logout_path
45
+ user, session_id = user_from_env(env)
46
+ if user
47
+ begin
48
+ Isomorfeus.session_store.remove(session_id: session_id)
49
+ cookie = "session=#{session_id}; SameSite=Strict; HttpOnly; Path=/; expires=Thu, 01 Jan 1970 00:00:00 UTC#{'; Secure' if Isomorfeus.production?}"
50
+ return [302, { 'Location' => '/', 'Set-Cookie' => cookie }, ["Logged out!"]]
51
+ ensure
52
+ Thread.current[:isomorfeus_user] = nil
53
+ Thread.current[:isomorfeus_session_id] = nil
42
54
  end
43
55
  end
56
+ return [302, { 'Location' => '/', 'Set-Cookie' => cookie }, ["Tried to log out!"]]
57
+ else
58
+ user, session_id = user_from_env(env)
59
+ if user
60
+ Thread.current[:isomorfeus_user] = user
61
+ Thread.current[:isomorfeus_session_id] = session_id
62
+ end
44
63
  begin
45
64
  result = @app.call(env)
46
65
  ensure
@@ -3,6 +3,10 @@ module Isomorfeus
3
3
  class ServerSocketProcessor
4
4
  include Isomorfeus::Transport::ServerProcessor
5
5
 
6
+ def initialize(user)
7
+ @user = user
8
+ end
9
+
6
10
  def on_message(client, data)
7
11
  if Isomorfeus.development?
8
12
  write_lock = Isomorfeus.zeitwerk_lock.try_write_lock
@@ -45,9 +49,7 @@ module Isomorfeus
45
49
  end
46
50
 
47
51
  def user(client)
48
- current_user = client.instance_variable_get(:@isomorfeus_user)
49
- return current_user if current_user
50
- Anonymous.new
52
+ @user ||= Anonymous.new
51
53
  end
52
54
  end
53
55
  end
@@ -1,5 +1,5 @@
1
1
  module Isomorfeus
2
2
  module Transport
3
- VERSION = '2.0.0.rc9'
3
+ VERSION = '2.0.2'
4
4
  end
5
5
  end
@@ -60,12 +60,13 @@ module LucidAuthentication
60
60
  end
61
61
 
62
62
  def promise_deauthentication_with_isomorfeus
63
- Isomorfeus::Transport.promise_send_path('Isomorfeus::Transport::Handler::AuthenticationHandler', 'logout', 'logout').then do |agent|
64
- `document.cookie = "session="`
65
- Isomorfeus.set_current_user(nil)
66
- Isomorfeus.force_init_store!
67
- agent.processed = true
68
- agent.response.key?(:success) ? true : raise('Logout failed!')
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
69
70
  end
70
71
  end
71
72
  else
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.0.0.rc9
4
+ version: 2.0.2
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-01-01 00:00:00.000000000 Z
11
+ date: 2022-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 7.0.0
19
+ version: 7.0.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 7.0.0
26
+ version: 7.0.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bcrypt
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -58,42 +58,42 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 3.13.10
61
+ version: 3.13.11
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 3.13.10
68
+ version: 3.13.11
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: opal
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 1.4.0
75
+ version: 1.4.1
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 1.4.0
82
+ version: 1.4.1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: isomorfeus-asset-manager
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.14.3
89
+ version: 0.14.5
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.14.3
96
+ version: 0.14.5
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: isomorfeus-hamster
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -114,28 +114,28 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 10.6.5
117
+ version: 10.6.11
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 10.6.5
124
+ version: 10.6.11
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: isomorfeus-policy
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: 2.0.0.rc9
131
+ version: 2.0.2
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - '='
137
137
  - !ruby/object:Gem::Version
138
- version: 2.0.0.rc9
138
+ version: 2.0.2
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: isomorfeus-redux
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -170,14 +170,14 @@ dependencies:
170
170
  requirements:
171
171
  - - '='
172
172
  - !ruby/object:Gem::Version
173
- version: 2.0.0.rc9
173
+ version: 2.0.2
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - '='
179
179
  - !ruby/object:Gem::Version
180
- version: 2.0.0.rc9
180
+ version: 2.0.2
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: rake
183
183
  requirement: !ruby/object:Gem::Requirement
@@ -272,9 +272,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
272
272
  version: '0'
273
273
  required_rubygems_version: !ruby/object:Gem::Requirement
274
274
  requirements:
275
- - - ">"
275
+ - - ">="
276
276
  - !ruby/object:Gem::Version
277
- version: 1.3.1
277
+ version: '0'
278
278
  requirements: []
279
279
  rubygems_version: 3.3.3
280
280
  signing_key: