Module: Alondra::SessionParser
Instance Method Summary collapse
- #marshall ⇒ Object
- #parse(websocket) ⇒ Object
- #parse_cookie(cookie) ⇒ Object
- #parse_token(token) ⇒ Object
- #session_key ⇒ Object
- #verifier ⇒ Object
Instance Method Details
#marshall ⇒ Object
53 54 55 |
# File 'lib/alondra/session_parser.rb', line 53 def marshall Rails.application.config.[:coder] end |
#parse(websocket) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/alondra/session_parser.rb', line 11 def parse(websocket) = websocket.request['cookie'] || websocket.request['Cookie'] token = websocket.request['query']['token'] if token.present? SessionParser.parse_token(token) elsif .present? SessionParser.() else Hash.new end end |
#parse_cookie(cookie) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/alondra/session_parser.rb', line 24 def () begin = .split(';') session_key = Rails.application.config.[:key] encoded_session = .detect{|c| c.include?(session_key)}.gsub("#{session_key}=",'').strip verifier.verify(CGI.unescape(encoded_session)) rescue ActiveSupport::MessageVerifier::InvalidSignature => ex Log.error "invalid session cookie: #{}" Hash.new rescue Exception => ex Log.error "Exception parsing session from cookie: #{ex.}" end end |
#parse_token(token) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/alondra/session_parser.rb', line 39 def parse_token(token) begin decoded_token = verifier.verify(token) ActiveSupport::JSON.decode(decoded_token) rescue ActiveSupport::MessageVerifier::InvalidSignature => ex Log.error "invalid session token: #{token}" Hash.new end end |
#session_key ⇒ Object
49 50 51 |
# File 'lib/alondra/session_parser.rb', line 49 def session_key Rails.application.config..key end |
#verifier ⇒ Object
7 8 9 |
# File 'lib/alondra/session_parser.rb', line 7 def verifier @verifier ||= ActiveSupport::MessageVerifier.new(Rails.application.config.secret_token) end |