ruby on rails - Getting data out of devise -
i'm migrating away rails. using same domain, i'll _session_id
cookie rails uses , can bring on old sessions
table.i use extract data (the user_id
) old session. can not tell how outside of rails.
within controller there's current_user
of course or session["warden.user.user.key"]
, how can take id, decrypt data in table, , pull stuff out on own (besides running old rails application , creating route on that returns info need , hitting new application)?
i'm not entirely sure best way, intrigued went down rabbit hole. works 4.1.10 app sessions stored in cookie. you'll want @ action pack's encryptedcookiejar class , active support's cachingkeygenerator , messageencryptor classes details.
obviously you'll need replace 2 strings start "the value…".
key_generator = activesupport::keygenerator.new('the value of secret_key_base config/secrets.yml', iterations: 1000) caching_key_generator = activesupport::cachingkeygenerator.new(key_generator) caching_key_generator.generate_key('encrypted cookie') caching_key_generator.generate_key('signed encrypted cookie') secret = caching_key_generator.generate_key('encrypted cookie') sign_secret = caching_key_generator.generate_key('signed encrypted cookie') encryptor = activesupport::messageencryptor.new(secret, sign_secret, serializer: actiondispatch::cookies::nullserializer) session_value = cgi::unescape('the value of session cookie') serialized_result = encryptor.decrypt_and_verify(session_value) result = marshal.load(serialized_result)
the result
, me, hash looks session hash in rails.
if doesn't work you, may using different serializer need replace marshal.load
whatever need. take @ serialized_result
, see.
Comments
Post a Comment