oivoodoo / devise_masquerade

Extension for devise, enable login as functionality. Add link to the masquerade_path(resource) and use it.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Current version of user_masquerade? returns always false

juansecaro opened this issue · comments

Basic app, I have checked older versions and it doesn't happen

(1.13.11 vs 0.40 and 1.2)

Just installed using Rails 6.1.6 and I have the same issue on Ruby 2.7.6

In the end I used v1.0 and it works so far.

gem 'devise_masquerade', '1.0'

No need to use a previous version. This happens if you don't run rails dev:cache to initialize your rails cache.

Fixed for me at least. It's noted in the troubleshoot section of the README but very easy to overlook.

Works on Rails 7.0.3 with the latest version of this gem (1.3.11).

The actual method that defines it is dynamic (so a bit harder to search for) but is located in lib/devise_masquerade/controllers/helpers.rb and looks like:

def user_masquerade?
  return false if current_user.blank?
  return false if session[user_helper_session_key].blank?

  ::Rails.cache.exist?(user_helper_session_key).present?
end

So if your Rails.cache doesn't exist the user_masquerade? method will always return false.

IMO the necessity to have dev cache enabled is a dealbreaker for me and a few others, so this requirement should be at the top of the README not at the bottom in troubleshooting :)

commented

@Jackson200 everything is reasonable, going to vacation in 2 days to hike for 7 days 🙂 and taking laptop I will try to make session as default method and create the major version. and cache as optionable way.

Have a great vacation @oivoodoo. Thanks for all your work. It's a long time since I did some overnight hiking. Hmm... I am dreaming a bit now :) Have fun.

commented

@Jackson200 @nolantait I've just created PR #113 . please check it out.

:session would be as default method to store the data. and cache is optionable to use via the configuration.

@oivoodoo this is amazing - I will try it out. Many thanks.

commented

@Jackson200 thank you! Let me know if it works now as expected

Hi @oivoodoo I'm on 2.0.0 but am getting an error that seems to be related to cookies?

JSON::GeneratorError at /accounts/masquerade
source sequence is illegal/malformed utf-8

I'm using Account with Devise, instead of the usual User.
devise :masqueradable in account.rb, and
before_action :masquerade_account! in application.rb

My masquerade_path link looks like

http://localhost:3000/accounts/masquerade?masquerade=BAh7CEkiCGdpZAY6BkVUSSIvZ2lkOi8vcG9rZXItdG8tY21zL0FjY291bnQvNz9leHBpcmVzX2luPTYwBjsAVEkiDHB1cnBvc2UGOwBUSSIPbWFzcXVlcmFkZQY7AFRJIg9leHBpcmVzX2F0BjsAVEkiHTIwMjItMTAtMTFUMTE6MTI6MDUuOTI2WgY7AFQ%3D--b5245f2ec5984522723ab7973854c4f2323993f7&masqueraded_resource_class=Account

That's about as far as I got this time. Any advice appreciated.
Cheers.

JSON::GeneratorError at /accounts/masquerade
source sequence is illegal/malformed utf-8

[Application Frames](http://localhost:3000/accounts/masquerade?masquerade=BAh7CEkiCGdpZAY6BkVUSSIvZ2lkOi8vcG9rZXItdG8tY21zL0FjY291bnQvNz9leHBpcmVzX2luPTYwBjsAVEkiDHB1cnBvc2UGOwBUSSIPbWFzcXVlcmFkZQY7AFRJIg9leHBpcmVzX2F0BjsAVEkiHTIwMjItMTAtMTFUMTE6MDc6NTAuMzAwWgY7AFQ%3D--393121aad7bdc02ffc0bda8ad96d4c6a4041b872&masqueraded_resource_class=Account#) [All Frames](http://localhost:3000/accounts/masquerade?masquerade=BAh7CEkiCGdpZAY6BkVUSSIvZ2lkOi8vcG9rZXItdG8tY21zL0FjY291bnQvNz9leHBpcmVzX2luPTYwBjsAVEkiDHB1cnBvc2UGOwBUSSIPbWFzcXVlcmFkZQY7AFRJIg9leHBpcmVzX2F0BjsAVEkiHTIwMjItMTAtMTFUMTE6MDc6NTAuMzAwWgY7AFQ%3D--393121aad7bdc02ffc0bda8ad96d4c6a4041b872&masqueraded_resource_class=Account#)
ActiveSupport::JSON::Encoding::JSONGemEncoder::EscapedString#to_json
activesupport (6.1.6.1) lib/active_support/core_ext/object/json.rb, line 40
ActiveSupport::JSON::Encoding::JSONGemEncoder::EscapedString#to_json
activesupport (6.1.6.1) lib/active_support/json/encoding.rb, line 57
JSON.generate
json (2.6.2) lib/json/common.rb, line 312
ActiveSupport::JSON::Encoding::JSONGemEncoder#stringify
activesupport (6.1.6.1) lib/active_support/json/encoding.rb, line 110
ActiveSupport::JSON::Encoding::JSONGemEncoder#encode
activesupport (6.1.6.1) lib/active_support/json/encoding.rb, line 35
ActiveSupport::JSON.encode
activesupport (6.1.6.1) lib/active_support/json/encoding.rb, line 22
ActionDispatch::Cookies::JsonSerializer.dump
actionpack (6.1.6.1) lib/action_dispatch/middleware/cookies.rb, line 547
ActionDispatch::Cookies::EncryptedKeyRotatingCookieJar#serialize
actionpack (6.1.6.1) lib/action_dispatch/middleware/cookies.rb, line 561
ActionDispatch::Cookies::EncryptedKeyRotatingCookieJar#commit
actionpack (6.1.6.1) lib/action_dispatch/middleware/cookies.rb, line 676
ActionDispatch::Cookies::EncryptedKeyRotatingCookieJar#[]=
actionpack (6.1.6.1) lib/action_dispatch/middleware/cookies.rb, line 496
ActionDispatch::Session::CookieStore#set_cookie
actionpack (6.1.6.1) lib/action_dispatch/middleware/session/cookie_store.rb, line 110
ActionDispatch::Session::CookieStore#commit_session
rack (2.2.4) lib/rack/session/abstract/id.rb, line 403
ActionDispatch::Session::CookieStore#context
rack (2.2.4) lib/rack/session/abstract/id.rb, line 268
ActionDispatch::Session::CookieStore#call
rack (2.2.4) lib/rack/session/abstract/id.rb, line 260
ActionDispatch::Cookies#call
actionpack (6.1.6.1) lib/action_dispatch/middleware/cookies.rb, line 689
ActiveRecord::Migration::CheckPending#call
activerecord (6.1.6.1) lib/active_record/migration.rb, line 601
block in ActionDispatch::Callbacks#call
actionpack (6.1.6.1) lib/action_dispatch/middleware/callbacks.rb, line 27
ActionDispatch::Callbacks#run_callbacks
activesupport (6.1.6.1) lib/active_support/callbacks.rb, line 98
ActionDispatch::Callbacks#call
actionpack (6.1.6.1) lib/action_dispatch/middleware/callbacks.rb, line 26
ActionDispatch::Reloader#call
actionpack (6.1.6.1) lib/action_dispatch/middleware/executor.rb, line 14
ActionDispatch::ActionableExceptions#call
actionpack (6.1.6.1) lib/action_dispatch/middleware/actionable_exceptions.rb, line 18
block in Rollbar::Middleware::Rails::RollbarMiddleware#call
rollbar (3.3.1) lib/rollbar/middleware/rails/rollbar.rb, line 25
Rollbar.scoped
rollbar (3.3.1) lib/rollbar.rb, line 145
Rollbar::Middleware::Rails::RollbarMiddleware#call
rollbar (3.3.1) lib/rollbar/middleware/rails/rollbar.rb, line 22
BetterErrors::Middleware#protected_app_call
better_errors (2.9.1) lib/better_errors/middleware.rb, line 87
BetterErrors::Middleware#better_errors_call
better_errors (2.9.1) lib/better_errors/middleware.rb, line 82
BetterErrors::Middleware#call
better_errors (2.9.1) lib/better_errors/middleware.rb, line 60
ActionDispatch::DebugExceptions#call
actionpack (6.1.6.1) lib/action_dispatch/middleware/debug_exceptions.rb, line 29
ActionDispatch::DebugExceptions#call_with_rollbar
rollbar (3.3.1) lib/rollbar/middleware/rails/show_exceptions.rb, line 22
WebConsole::Middleware#call_app
web-console (4.2.0) lib/web_console/middleware.rb, line 132
block in WebConsole::Middleware#call
web-console (4.2.0) lib/web_console/middleware.rb, line 19
WebConsole::Middleware#call
web-console (4.2.0) lib/web_console/middleware.rb, line 17
ActionDispatch::ShowExceptions#call
actionpack (6.1.6.1) lib/action_dispatch/middleware/show_exceptions.rb, line 33
Rails::Rack::Logger#call_app
railties (6.1.6.1) lib/rails/rack/logger.rb, line 37
block in Rails::Rack::Logger#call
railties (6.1.6.1) lib/rails/rack/logger.rb, line 26
block in ActiveSupport::Logger#tagged
activesupport (6.1.6.1) lib/active_support/tagged_logging.rb, line 99
ActiveSupport::Logger::SimpleFormatter#tagged
activesupport (6.1.6.1) lib/active_support/tagged_logging.rb, line 37
ActiveSupport::Logger#tagged
activesupport (6.1.6.1) lib/active_support/tagged_logging.rb, line 99
Rails::Rack::Logger#call
railties (6.1.6.1) lib/rails/rack/logger.rb, line 26
Rails::Rack::Logger#call_with_quiet_ahoy
ahoy_matey (4.1.0) lib/ahoy/engine.rb, line 22
Sprockets::Rails::QuietAssets#call
sprockets-rails (3.4.2) lib/sprockets/rails/quiet_assets.rb, line 13
ActionDispatch::RemoteIp#call
actionpack (6.1.6.1) lib/action_dispatch/middleware/remote_ip.rb, line 81
RequestStore::Middleware#call
request_store (1.5.1) lib/request_store/middleware.rb, line 19
ActionDispatch::RequestId#call
actionpack (6.1.6.1) lib/action_dispatch/middleware/request_id.rb, line 26
Rack::MethodOverride#call
rack (2.2.4) lib/rack/method_override.rb, line 24
Rack::Runtime#call
rack (2.2.4) lib/rack/runtime.rb, line 22
ActionDispatch::Executor#call
actionpack (6.1.6.1) lib/action_dispatch/middleware/executor.rb, line 14
ActionDispatch::Static#call
actionpack (6.1.6.1) lib/action_dispatch/middleware/static.rb, line 24
Rack::Sendfile#call
rack (2.2.4) lib/rack/sendfile.rb, line 110
ActionDispatch::HostAuthorization#call
actionpack (6.1.6.1) lib/action_dispatch/middleware/host_authorization.rb, line 148
PokerToCMS::Application#call
railties (6.1.6.1) lib/rails/engine.rb, line 539
Puma::Configuration::ConfigMiddleware#call
puma (5.6.4) lib/puma/configuration.rb, line 252
block in Puma::Server#handle_request
puma (5.6.4) lib/puma/request.rb, line 77
Puma::ThreadPool#with_force_shutdown
puma (5.6.4) lib/puma/thread_pool.rb, line 340
Puma::Server#handle_request
puma (5.6.4) lib/puma/request.rb, line 76
Puma::Server#process_client
puma (5.6.4) lib/puma/server.rb, line 441
block in Puma::ThreadPool#spawn_thread
commented

Hi @Jackson200 . Not sure for now probably it's about what I store to the session (value) . Let me give a try during the evening and write you back it. Probably I can give a try to save as less as possible to session.

Hi @oivoodoo ... sorry to pile on but I'm getting the exact same error as @Jackson200. It seems that the verifier -> secret is malformed?

commented

@rkiller Hi

could you give a try https://github.com/oivoodoo/devise_masquerade/releases/tag/v2.0.1 ?

if it resolves the issue otherwise I will continue research today.

I missed that I forgot to release version 2.0.1 to rubygems with fixes in session the signed object.

Thank you!

I had exactly the same problem today with version 2.0.0 as @Jackson200 and @rkiller, bumping to 2.0.1 fixed it 🙏

2.0.1 Fixed it! Thanks @oivoodoo

commented

Thank you everyone for pointing out the issue! I will close the issue and let me know if it would require anything to add it.