Class: Utopia::Session
- Inherits:
-
Object
- Object
- Utopia::Session
- Defined in:
- lib/utopia/session.rb,
lib/utopia/session/lazy_hash.rb
Overview
Stores all session data client side using a private symmetric encrpytion key.
Defined Under Namespace
Classes: LazyHash
Constant Summary collapse
- RACK_SESSION =
"rack.session".freeze
- CIPHER_ALGORITHM =
"aes-256-cbc"
- KEY_LENGTH =
32
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, secret:, **options) ⇒ Session
constructor
A new instance of Session.
Constructor Details
#initialize(app, secret:, **options) ⇒ Session
Returns a new instance of Session.
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/utopia/session.rb', line 33 def initialize(app, secret:, **) @app = app @cookie_name = .delete(:cookie_name) || (RACK_SESSION + ".encrypted") salt = OpenSSL::Random.random_bytes(16) @key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(secret, salt, 1, KEY_LENGTH) @options = { :domain => nil, :path => "/", :expires_after => nil }.merge() end |
Instance Method Details
#call(env) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/utopia/session.rb', line 47 def call(env) session_hash = prepare_session(env) status, headers, body = @app.call(env) if session_hash.changed? commit(session_hash.values, headers) end return [status, headers, body] end |