isomorfeus-transport 2.0.0.rc10 → 2.0.3
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 +3 -3
- data/lib/isomorfeus/transport/config.rb +6 -4
- data/lib/isomorfeus/transport/handler/authentication_handler.rb +3 -18
- data/lib/isomorfeus/transport/rack_middleware.rb +32 -13
- data/lib/isomorfeus/transport/server_socket_processor.rb +5 -3
- data/lib/isomorfeus/transport/version.rb +1 -1
- data/lib/lucid_authentication/mixin.rb +7 -6
- metadata +12 -12
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 93245ae3a021e4b349684a57b655ac9a0d382aaf6dd0903ecbe780d1be636eb7
         | 
| 4 | 
            +
              data.tar.gz: 7636567bb65d92cf8085ac320cb8fcc86c1cc990a49705583c9358408b95fa7c
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 9aa80c35739e28cf78af788026f8cf3bf417ab54a6fc3d9019899e499bda6acd4862d4faedc902636e375bfee5f06dc89e5089f390134a0fea834d5cad022792
         | 
| 7 | 
            +
              data.tar.gz: 0a6e0f1375ceed9327fdcb1cc0d489e11b4e250ba5e1ad629121604e24dd6ff90ca9348e26b631f2bbfd15620d430543aca85c3e2ec9a3e07cbe44711f07fddf
         | 
    
        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/ | 
| 27 | 
            -
            - [Channels (PubSub)](https://github.com/isomorfeus/isomorfeus-project/blob/master/ | 
| 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 | 
| 172 | 
            -
                  Isomorfeus::Transport::HamsterSessionStore.new(store_path) | 
| 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 | 
| 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 | | 
| 10 | 
            -
                        if  | 
| 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  | 
| 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 | 
            -
                         | 
| 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 | 
            -
                     | 
| 31 | 
            -
                       | 
| 32 | 
            -
                      if  | 
| 33 | 
            -
                         | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
                           | 
| 37 | 
            -
             | 
| 38 | 
            -
                           | 
| 39 | 
            -
             | 
| 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 | 
            -
                     | 
| 49 | 
            -
                    return current_user if current_user
         | 
| 50 | 
            -
                    Anonymous.new
         | 
| 52 | 
            +
                    @user ||= Anonymous.new
         | 
| 51 53 | 
             
                  end
         | 
| 52 54 | 
             
                end
         | 
| 53 55 | 
             
              end
         | 
| @@ -60,12 +60,13 @@ module LucidAuthentication | |
| 60 60 | 
             
                  end
         | 
| 61 61 |  | 
| 62 62 | 
             
                  def promise_deauthentication_with_isomorfeus
         | 
| 63 | 
            -
                     | 
| 64 | 
            -
             | 
| 65 | 
            -
             | 
| 66 | 
            -
                      Isomorfeus. | 
| 67 | 
            -
                       | 
| 68 | 
            -
             | 
| 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. | 
| 4 | 
            +
              version: 2.0.3
         | 
| 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- | 
| 11 | 
            +
            date: 2022-01-21 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activesupport
         | 
| @@ -86,14 +86,14 @@ dependencies: | |
| 86 86 | 
             
                requirements:
         | 
| 87 87 | 
             
                - - "~>"
         | 
| 88 88 | 
             
                  - !ruby/object:Gem::Version
         | 
| 89 | 
            -
                    version: 0.14. | 
| 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. | 
| 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. | 
| 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. | 
| 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. | 
| 131 | 
            +
                    version: 2.0.3
         | 
| 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. | 
| 138 | 
            +
                    version: 2.0.3
         | 
| 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. | 
| 173 | 
            +
                    version: 2.0.3
         | 
| 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. | 
| 180 | 
            +
                    version: 2.0.3
         | 
| 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:  | 
| 277 | 
            +
                  version: '0'
         | 
| 278 278 | 
             
            requirements: []
         | 
| 279 279 | 
             
            rubygems_version: 3.3.3
         | 
| 280 280 | 
             
            signing_key:
         |