-
Notifications
You must be signed in to change notification settings - Fork 240
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
Documentation and authenticate_user!
#188
Comments
Hello @huttarichard! Integration with other authentication methods (namely Devise strategies) is documented in its own section of the If you ask Devise to By attempting token authentication before the Devise authentication, however, you are able to authenticate users from their authentication token, or if token authentication credentials were missing or incorrect, by any of the Devise strategies. If these do also fail, then Devise raises an exception an the access is denied, which is what you wanted. # Deny access if all authentication methods fail:
acts_as_token_authentication_handler_for User, fallback: :none
before_action :authenticate_user!
# That's to say: attempt to authenticate users from their token, then fallback to
# the usual Devise behaviour if token authentication fails.
# That's what the fallback option was created in the first place:
acts_as_token_authentication_handler_for User, fallback: :devise
# And fallback: :devise is in fact the default _Simple Token Authentication_ behaviour.
# The previous configuration could be simplified further:
acts_as_token_authentication_handler_for User Also, when the token authenticatable model you defined is I'd love to hear how you think the documentation could be improved. Writing documentation requires to find a balance between precise and concise explanations, and sometimes we get it definitely wrong! I've been trying to attend the need for detailed examples in #96 for a while, if you feel to jump in and start discussing some ideas, that could be a great contribution indeed! I hope the explanation helped : ) |
@gonzalo-bulnes I also think that the documentation needs to be improved on this point, and it took me a long time until I found this post :) Your explanation here is already a great start for an improvement ! Anyways, If I understood correctly:
Even having understood that, I'm having issues. Take a look at my example controller:
If I try to access /dashboard without the token params, it prompts me for password just like before, which shows that devise fallback is being triggered (I guess). But if I pass the params in the URL, like
This instance variable @last_contacts is generated from a method that is inside ApplicationController, from which, as you saw above, DashboardController derives from:
Sorry for pasting all this code, but if I remove the @last_contacts loop from the layout, the authentication works fine. This should be an issue tough, since I shouldn't have to modify my views and layouts just for authentication to work properly if with Devise this was not being required. My versions; |
@gonzalo-bulnes The exception is happening because current_user is not set. I read #86 but it didn't help. I can log in with Devise fine, it's a Rails app running in production for more then one year. |
@gonzalo-bulnes My colleague, checking out at the exactly same branch as I am, is not even being able to try to debug our issue. As soon as he tries to open any view, he gets an exception from within a view that is deprecated and shouldn't even be called. This is so bizarre I had him to open a VNC session with me so I could believe he was not on a different branch. --- Edit: this was our fault. We were actually using 2 different controllers, and one of the controllers had Anyways, the bug persists: |
Update: this might be related (I know it's another gem, but it's a gem that supposedly does that same as this without being simple at all), but I still couldn't solve it (I tried setting |
Hi @feliperaul, Starting by your first comment about the
Now to discuss the |
I just came across one issue, I have both
authenticate_user!
,acts_as_token_authentication_handler_for User
since I used devise beforeand this will not work due to same before_filter handlers....
I think this should be mentioned in documentation... or you don't think so?
The text was updated successfully, but these errors were encountered: