-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: config.enable_standard_devise_support = true returns wrong current_user #1060
Comments
@KelseyDH thanks so much for your report! Seems like a pretty complicated setup. Do you think you could solve this through code/a pull request? If so we'd welcome it! |
@zachfeldman I definitely have a hacky setup for my routes, which reflects trying to support a classic devise web app endpoint page for password resets, within a Rails Api-only app using Getting the two to play together has been a tremendous challenge, one that I haven't still completely resolved. E.g. one current problem with my setup is that I haven't been completely successful in subclassing ApplicationController into separate Rails web and Rails Api endpoints for (Any advice on how to properly subclass This quirk I suspect, which is a combination of |
@KelseyDH You may want to check out this issue (see my comment at the bottom), its related issues, and also this one. We had the same symptoms that you are describing, and turning off |
I recently started setting up
In addition to wrong
The line 41 in which actually doesn't take any argument. Update Update 2 Working more on this, I found that the issue might be because of session being persisted when a api request is submitted. Due to which the next time even if I don't pass Side note: Thank you for developing this gem. |
I have seen a similar thing. I use Paw to make HTTP requests and it has these settings that help prove what's going on: If I remove the 5 devise_token_auth HTTP headers and leave "Automatically Send Cookies", the user's session is still used to authenticate them. This was surprising to me as I assumed if I didn't have the headers, devise_token_auth would barf. If I uncheck "Automatically Send Cookies", the 5 devise_token_auth HTTP headers are required. I found a similar behavior in one of my clients that by default stores cookies. Even if tokens became invalidated, the session would be used to "revive" the client. I'm also seeing a really annoying issue with Fun stuff! |
Request and response headers:
Described below.
Rails Stacktrace: this can be found in the
log/development.log
of your API.Environmental Info: My app uses both
devise
anddevise_token_auth
, which I achieve by subclassing ApplicationController intoApiController
andApplicationController
. One inheriting fromApplicationController::Base
the otherApplicationController::API
Routes: I'm using both
devise
anddevise_token_auth
Gems: Using devise web. Also using
paperTrail
gem, which writes a copy of the Users table over to UserVersion.Custom Overrides: I'm (trying) to namespace both devise and devise_token_auth into separate controllers. But I have run into problems completely doing this (explained below).
Custom Frontend: iPhone & Android native clients, Postman for testing
Bug setup
In my app, my API consumers can switch between child and parent users, with the Bearer token
uid / client / access-token
being the mechanism for how my API consumers can switch between users.However they were complaining about getting back incorrect data, with data from the wrong user getting sent back to them. After investigating I found their concerns to be true, with
devise_token_auth
returning back incorrect users based on the headers it is sent.To replicate. I created two users with the same password:
user 1:
[email protected]
user 2:
[email protected]
First, log in with user 1:
receiving correctly back headers corresponding to uid =
[email protected]
/ user 1:Next, log in with user 2:
receiving correctly back headers corresponding to uid =
[email protected]
/ user 2:Bug
Now here's where the bug happens. When I copy the headers for these two separate users into two separate requests and hit an app endpoint requiring authentication. When
config.enable_standard_devise_support
istrue
the api returns back the incorrect current_user (confirmed with byebug), always defaulting to the first user that hit the endpoint (user 1), instead of user 2.As proof, attached is a screenshot where you can see
[email protected]
(user 2) sending a token request and getting a response back with authentication headers meant for[email protected]
(user 1):Restarting the server had no effect on the Postman requests.
Fix for now
When I changed
config.enable_standard_devise_support = false
the problem went away. Consequently I strongly suspect there is an issue withDeviseTokenAuth.enable_standard_devise_support
, such as in the way it gets invoked withinset_user_by_token
:The text was updated successfully, but these errors were encountered: