isomorfeus-transport 1.0.0.zeta14 → 1.0.0.zeta15

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: 2da7f01a24198876e721b9eee2365d39d71e849a8a9df0391f2bfde73d8891e7
4
- data.tar.gz: 7b50a07f4141181f7626068d549e6b6e404c9f3ac1a135a1d5079ebe7cd40a74
3
+ metadata.gz: 1b194ed58cc86f8f5fa2b176f57bf9c2f61422fe4ed9ed408d6de080a2439008
4
+ data.tar.gz: 3a990c000db8b9dbb297d24140fd975386407809c0db025aa1536773f7302d43
5
5
  SHA512:
6
- metadata.gz: e412f4955497cdca05527b08433f97911d487859bae283f40ad7505521d92777707c316d5d2d1ffc7fd6abd8d46362763eb99335543bc57b80a4b812ab2b99a9
7
- data.tar.gz: 0577e8b840f07d4d2dcb627a713f1b02a8f02fcc3963e5e7642326347d51e21bfc79472a141faf88248dd87e1dc685fb5ffe68e840994829dbbc88a4d80fcafa
6
+ metadata.gz: 253fdb266e2cce4062a3dcb6081ff846455ffc960c2ca2c2cceaf61430ae97044444c942016ad63951dbd77fe72e8512535ba4e0245e2047f1b81b98c601ea49
7
+ data.tar.gz: fd5a2d29968070c2d98ffda434a54f0c4f03ca56289427de88e1d572ff72444060fd6ae43588c7d35960fbf6f1c9df308ccfeac391fcf4ba1b88ba2c894c778c
data/README.md CHANGED
@@ -30,77 +30,7 @@ Client and Server:
30
30
  Server only:
31
31
  - Isomorfeus.middlewares - all the rack middlewares to load
32
32
 
33
- ## Authentication
33
+ ## Usage
34
34
 
35
- For authentication in isomorfeus there is a class `Anonymous`, so whenever no user is logged in, the anonymous user is passed on to operations
36
- or data loads. In my opinion it is more true than no user (nil), because in fact there probably is a user, just the user is unknown.
37
- The Anonymous user has a default policy that allows everything, the user will respond to .authorized?(whatever) always with true by default.
38
- Of course, the developer can add a Policy easily, to deny certain operations or data loads, or whatever or deny everything:
39
- ```ruby
40
- class AnonymousPolicy < LucidPolicy::Base
41
- deny all
42
- end
43
- ```
44
- For more information about policy see [the policy docs](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-policy/README.md).
45
-
46
- A class representing a user should be a LucidNode and include LucidAuthentication::Mixin:
47
- ```ruby
48
- class User < LucidGenericDocument::Base
49
- include LucidAuthentication::Mixin
50
- authentication do |user:, pass:|
51
- # should return either a User instance or a Promise which reselves to a User instance
52
- end
53
- end
54
- ```
55
- With that its possible to do on the client (or server):
56
- ```ruby
57
- User.promise_login(user: user_identifier, pass: user_password_or_token).then do |user|
58
- # do something with user
59
- end
60
- ```
61
- or later on:
62
- ```ruby
63
- user.promise_logout
64
- ```
65
- The authentication in isomorfeus is prepared for external or alternate authentication schemes, example:
66
- ```ruby
67
- User.promise_login(user: user_identifier, pass: token, :facebook).then do |user|
68
- # do something with user
69
- end
70
- ```
71
- will call:
72
- ```ruby
73
- User.promise_authentication_with_facebook(user: user_identifier, pass: token)
74
- ```
75
- which would have to be implemented.
76
-
77
- ## LucidChannel
78
-
79
- Isomorfeus-transport provides the LucidChannel::Mixin and LucidChannel::Base class.
80
- These can be used for subscriptions and publishing messages.
81
-
82
- ### Subscriptions
83
- ```ruby
84
- class MyChannel < LucidChannel::Base
85
- end
86
-
87
- # subscribe to channel
88
- MyChannel.subscribe
89
-
90
- # unsubscribe
91
- MyChannel.unsubscribe
92
- ```
93
-
94
- ### Processing messages
95
- ```ruby
96
- class MyChannel < LucidChannel::Base
97
- on_message do |message|
98
- puts "received: " + message
99
- end
100
- end
101
- ```
102
-
103
- ### Sending messages
104
- ```ruby
105
- MyChannel.send_message('uiuiui')
106
- ```
35
+ - [Authentication and Current User](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-policy/docs/authentication.md)
36
+ - [Channels (PubSub)](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-policy/docs/channels.md)
@@ -23,6 +23,7 @@ else
23
23
  require 'websocket/driver'
24
24
  require 'active_support'
25
25
  require 'iodine'
26
+ require 'isomorfeus/transport/thread_session_store'
26
27
  require 'isomorfeus/config'
27
28
  require 'isomorfeus/promise'
28
29
  require 'isomorfeus/transport/version'
@@ -19,6 +19,7 @@ module Isomorfeus
19
19
  else
20
20
  class << self
21
21
  attr_accessor :api_websocket_path
22
+ attr_accessor :session_store
22
23
 
23
24
  def add_middleware(middleware)
24
25
  Isomorfeus.middlewares << middleware
@@ -130,6 +131,8 @@ module Isomorfeus
130
131
  Thread.current[:isomorfeus_pub_sub_client]
131
132
  end
132
133
  end
134
+
135
+ self.session_store = Isomorfeus::Transport::ThreadSessionStore.new # dont use this one, but we keep it here to have at least something
133
136
  end
134
137
 
135
138
  # defaults
@@ -5,10 +5,10 @@ module Isomorfeus
5
5
  TIMEOUT = 30
6
6
 
7
7
  on_request do |response_agent|
8
- result = { error: 'Authentication failed' }
9
8
  # promise_send_path('Isomorfeus::Transport::Handler::AuthenticationHandler', 'login', user_class_name, user_identifier, user_password)
10
9
  response_agent.request.each_key do |login_or_logout|
11
10
  if login_or_logout == 'login'
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
14
14
  tries += 1
@@ -32,26 +32,23 @@ module Isomorfeus
32
32
  end
33
33
  end
34
34
  if user
35
+ session_cookie = "session=#{SecureRandom.uuid};max-age=2592000"
35
36
  Isomorfeus.pub_sub_client.instance_variable_set(:@isomorfeus_user, user)
36
37
  Isomorfeus.pub_sub_client.instance_variable_set(:@isomorfeus_authentication_tries, nil)
37
- # TODO store session in db and supply session cookie: session_cookie: uuid or so
38
- response_agent.agent_result = { success: 'ok', data: user.to_transport }
38
+ Isomorfeus.pub_sub_client.instance_variable_set(:@isomorfeus_session_cookie, session_cookie)
39
+ Isomorfeus.session_store.add(cookie: session_cookie, user: user)
40
+ response_agent.agent_result = { success: 'ok', data: user.to_transport, session_cookie: session_cookie }
39
41
  end
40
42
  end
41
43
  elsif login_or_logout == 'logout'
42
44
  begin
43
- promise = Isomorfeus.current_user.promise_logout
44
- # TODO remove session from db
45
- # response_agent.agent_result = { success: 'ok', data: user.to_transport }
46
- unless promise.realized?
47
- start = Time.now
48
- until promise.realized?
49
- break if (Time.now - start) > TIMEOUT
50
- sleep 0.01
51
- end
52
- end
45
+ # bogus
46
+ session_cookie = nil
53
47
  ensure
54
48
  Isomorfeus.pub_sub_client.instance_variable_set(:@isomorfeus_user, nil)
49
+ Isomorfeus.pub_sub_client.instance_variable_set(:@isomorfeus_authentication_tries, nil)
50
+ Isomorfeus.pub_sub_client.instance_variable_set(:@isomorfeus_session_cookie, nil)
51
+ Isomorfeus.session_store.remove(cookie: session_cookie)
55
52
  response_agent.agent_result = { success: 'ok' }
56
53
  end
57
54
  end
@@ -2,7 +2,9 @@ module Isomorfeus
2
2
  module Transport
3
3
  module Middlewares
4
4
  def use_isomorfeus_middlewares
5
+ STDOUT.puts "Isomorfeus is using the following middlewares:"
5
6
  Isomorfeus.middlewares.each do |isomorfeus_middleware|
7
+ STDOUT.puts "#{isomorfeus_middleware}"
6
8
  use isomorfeus_middleware
7
9
  end
8
10
  end
@@ -0,0 +1,20 @@
1
+ module Isomorfeus
2
+ module Transport
3
+ class ThreadSessionStore
4
+
5
+ def add(cookie:, user:)
6
+ store[cookie] = user
7
+ end
8
+
9
+ def remove(cookie:)
10
+ store.delete(cookie)
11
+ end
12
+
13
+ private
14
+
15
+ def store
16
+ Thread.current[:isomorfeus_session_store] ||= {}
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,5 +1,5 @@
1
1
  module Isomorfeus
2
2
  module Transport
3
- VERSION = '1.0.0.zeta14'
3
+ VERSION = '1.0.0.zeta15'
4
4
  end
5
5
  end
@@ -1,10 +1,13 @@
1
1
  module LucidAuthentication
2
2
  module Mixin
3
+ def anonymous?
4
+ self.class == Anonymous
5
+ end
6
+
3
7
  if RUBY_ENGINE == 'opal'
4
8
  def self.included(base)
5
-
6
9
  base.instance_exec do
7
- def authentication(&block)
10
+ def execute_login(&block)
8
11
  end
9
12
 
10
13
  def promise_login(user: nil, pass: nil, scheme: :isomorfeus)
@@ -61,8 +64,8 @@ module LucidAuthentication
61
64
  Isomorfeus.add_valid_user_class(base)
62
65
 
63
66
  base.instance_exec do
64
- def authentication(&block)
65
- @authentication_block = block
67
+ def execute_login(&block)
68
+ @execute_login_block = block
66
69
  end
67
70
 
68
71
  def promise_login(user: nil, pass: nil, scheme: :isomorfeus)
@@ -70,7 +73,7 @@ module LucidAuthentication
70
73
  end
71
74
 
72
75
  def promise_authentication_with_isomorfeus(user: nil, pass: nil)
73
- promise_or_user = @authentication_block.call(user: user, pass: pass)
76
+ promise_or_user = @execute_login_block.call(user: user, pass: pass)
74
77
  if promise_or_user.class == Promise
75
78
  promise_or_user
76
79
  else
@@ -80,6 +83,16 @@ module LucidAuthentication
80
83
  end
81
84
  end
82
85
 
86
+ def encrypt_password(password, password_confirmation)
87
+ raise "Password and confirmation don't match!" unless password == password_confirmation
88
+ BCrypt::Password.create(password).to_s
89
+ end
90
+
91
+ def passwords_match?(encrypted_password, given_password)
92
+ bcrypt_pass = BCrypt::Password.new(encrypted_password)
93
+ bcrypt_pass == given_password
94
+ end
95
+
83
96
  def promise_logout(scheme: :isomorfeus)
84
97
  send("promise_deauthentication_with_#{scheme}")
85
98
  end
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: 1.0.0.zeta14
4
+ version: 1.0.0.zeta15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-28 00:00:00.000000000 Z
11
+ date: 2020-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '6.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bcrypt
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.1.13
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.1.13
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: iodine
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -86,28 +100,28 @@ dependencies:
86
100
  requirements:
87
101
  - - ">="
88
102
  - !ruby/object:Gem::Version
89
- version: 16.12.14
103
+ version: 16.12.17
90
104
  type: :runtime
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - ">="
95
109
  - !ruby/object:Gem::Version
96
- version: 16.12.14
110
+ version: 16.12.17
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: isomorfeus-policy
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - '='
102
116
  - !ruby/object:Gem::Version
103
- version: 1.0.0.zeta14
117
+ version: 1.0.0.zeta15
104
118
  type: :runtime
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - '='
109
123
  - !ruby/object:Gem::Version
110
- version: 1.0.0.zeta14
124
+ version: 1.0.0.zeta15
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: websocket-driver
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -128,14 +142,14 @@ dependencies:
128
142
  requirements:
129
143
  - - '='
130
144
  - !ruby/object:Gem::Version
131
- version: 1.0.0.zeta14
145
+ version: 1.0.0.zeta15
132
146
  type: :development
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
150
  - - '='
137
151
  - !ruby/object:Gem::Version
138
- version: 1.0.0.zeta14
152
+ version: 1.0.0.zeta15
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: opal-webpack-loader
141
155
  requirement: !ruby/object:Gem::Requirement
@@ -197,6 +211,7 @@ files:
197
211
  - lib/isomorfeus/transport/response_agent.rb
198
212
  - lib/isomorfeus/transport/server_processor.rb
199
213
  - lib/isomorfeus/transport/server_socket_processor.rb
214
+ - lib/isomorfeus/transport/thread_session_store.rb
200
215
  - lib/isomorfeus/transport/version.rb
201
216
  - lib/isomorfeus/transport/websocket.rb
202
217
  - lib/lucid_authentication/mixin.rb