I am using a token based authentication for a rails json api. I have rewritten methods in the devise sessions and registrations controller since devise deprecated the token_authenticable module. Is devise in this state unnecessary for an api? Is devise still more secure for a purpose like this in which I'm writing the token authentication myself?
For example, according to a devise gist, I should use the following code to authenticate a user from a token:
def authenticate_user_from_token!
email = params[:user_email].presence
user = email && User.find_by_email(email)
if user && Devise.secure_compare(user.authentication_token, params[:auth_token])
sign_in user, store: false
end
end
I believe params[:auth_token]
would not work for an api that send the token in the header. I'm also not sure what purpose sign_in user
would serve in a json api. I can either keep devise and continue to modify it for tokens or follow e.g. https://github.com/danahartweg/authenticatable_rest_api/ for a custom solution.