-
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
Having both devise and devise_token_auth #120
Comments
I'm having a hard time understanding this issue. Can you please elaborate? For example, what do you mean by "stateful"? Also, have you read this section of the README? |
Ok I will try to be more clear. We are migrating page after page to angularJS so I was wondering if it is possible to have devise_token_auth on pages with angular and my standard Devise for my old pages. |
@casertap Yes, you can have normal (cookie) based devise for your legacy pages and, as you migrate to angular, use DeviseTokenAuth for your new angular pages. The way I'm handling it now is having the |
@nickL - that sounds like a good strategy. Should we incorporate this behavior into the gem? |
@lynndylanhurley: Yeah, I think it may be useful. Here's a quick snippet. Let me know if I'm on the right track and I'll clean it up more and submit a PR: def set_user_by_token(mapping=nil)
# determine target authentication class
rc = resource_class(mapping)
# no default user defined
return unless rc
# user has already been found and authenticated
return @resource if @resource and @resource.class == rc
# parse header for values necessary for authentication
uid = request.headers['uid']
@token = request.headers['access-token']
@client_id = request.headers['client']
@client_id ||= 'default'
#**** Money line here... looking for user via warden first..****
#*********************************************************************
#
if warden.user
user = warden.user
user.provider ||= "email"
user.uid ||= user.email
user.save if user.changed?
sign_in(:user, user, store: false, bypass: true)
return @resource = user
else
return false unless @token
# client_id isn't required, set to 'default' if absent
# mitigate timing attacks by finding by uid instead of auth token
user = uid && rc.find_by_uid(uid) |
Crap, that |
@nickL - looks good to me! If you have time to send a PR I'll merge ASAP. |
Cool! I'll whip up a PR and add some tests. Thanks dude! On Wed, Mar 25, 2015 at 12:26 PM -0700, "Lynn Dylan Hurley" [email protected] wrote: @nickL - looks good to me! If you have time to send a PR I'll merge ASAP. — |
@nickL it is an awesome solution thanks a lot. |
I'm not sure if this is the best issue to comment on or if I should make a new one. I am using ActiveAdmin together with this gem and have noticed that /admin/logout (which results in "active_admin/devise/sessions#destroy" and presumably maps to the normal Devise sign-out) sets "current_user" to nil, but /auth/sign_out does not. This is leading to some inconsistencies where I can sign out on using /auth/sign_out, but can directly go to my AA page at /admin and still be signed in... |
There's now documentation in the |
The documentation on this is very difficult to piece together. I’d try to rewrite it but I haven’t gotten my standard Devise actions working again since adding the gem. From the readme:
Why is the config line commented out? Shouldn’t it be |
Can someone help me? What is the solution to this bug? I've been crawling around the internet. |
I have the issue with the latest version. Original devise seems not to be working after adding this gem |
For me, it gives me an error here:
The error message is: wrong number of arguments (given 1, expected 0) Apparently, Devise has changed that resource_class no longer accepts an argument? Is that is what is causing this to fail? Because right now, it never gets to the line if |
It seems like a lot of people are having the same issue here, dating back to 2015 and we are now in January 2017. I think what happened is that the Devise gem made updates that adversely influenced the behavior of this gem. Since this gem is no longer maintained, this gem can no longer work in conjunction with Devise (for the web). I assume the solution now is to migrate to this gem: https://github.com/gonzalo-bulnes/simple_token_authentication |
@JohnMerlino2 Is it true what you said: "Since this gem is no longer maintained, this gem can no longer work in conjunction with Devise (for the web)"? Because this repo seems active and last commit was a month ago. |
I was having the same issue where i need to sign a user into both
In the ApplicationController I added:
Finally in views/layouts/application.html.haml i added:
I realize that this is a little hacky and that my code could be a lot cleaner; that said i wanted to share it with you as a possible solution for people looking to authenticate with both |
I was working in a similar case where I needed to use both, devise+devise_token_auth in a spree application. I was trying to implement authentication for spree_api and migrating the authentication of spree system(Full Stack App) to devise.
In the API controller I included the regular DeviseTokenAuth concern to manage auth in the app that controls this application_controller.rb. Note that this controller inherits from the main application_controller.
This controller is, well, natural behavior of devise. I just needed to add the before action method.
Our main application_controller.rb looks like this. You need to keep the CSRF token protection but you can avoid it when an API request arrive. |
I have a lot of trouble to set up my application with both devise and devise_token_auth.
We are slowly migrating from a rails server-side rendering to an angularjs application.
The problem is that I want to have a way to log in and have part of my website with angular and part without angular (yet).
It seems that with devise_token_auth the current_user is not statefull, that is a problem for me because I need to log in ones and then I just need to check if current_user exists.
At least I need to do that until the migration is complete and I can totally switch to a token auth.
Do you have an idea on how to solve my problem?
The text was updated successfully, but these errors were encountered: