Skip to content
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

Q: Getting NoAdapterAvailableError? (R: Check the declarations order in your Gemfile!) #158

Closed
emirkin opened this issue Apr 6, 2015 · 4 comments
Labels
question When closed, this issue will become part of the FAQ.

Comments

@emirkin
Copy link

emirkin commented Apr 6, 2015

I am getting SimpleTokenAuthentication::NoAdapterAvailableError with Mongo 4.0.2

class Account
  include Mongoid::Document

  acts_as_token_authenticatable
  field :authentication_token
  ...
class ApplicationController < ActionController::Base
  acts_as_token_authentication_handler_for Account
@gonzalo-bulnes
Copy link
Owner

Hello @emirkin,

I think I know what's going on: does simple_token_authentication appear before mongoid in your Gemfile? Try swapping them.

# Gemfile

gem 'mongoid', '~> 4.0'
gem 'simple_token_authentication', '~> 1.0'

Why?

When you start your Rails app, the dependencies are required by Bundler, which loads them in the same order they are declared in the Gemfile (unless they depend one on another).

# config/application.rb

# Requiring 'mongoid' at this point would solve the issue too,
# but you don't want to do that if you can swap the gems in you Gemfile.
Bundler.require(*Rails.groups)
# ...

Simple Token Authentication in fact does not depend on Mongoid (you could be using Active Record) and Bundler has no reason to load them in any specific order, which is sad because by design the MongoidAdapter is not loaded unless the Mongoid constant is defined.

Please confirm to me that swapping does the trick!

@emirkin
Copy link
Author

emirkin commented Apr 8, 2015

Ha! I have just discovered just that. I wish I've seen your note yesterday :-)

@emirkin emirkin closed this as completed Apr 8, 2015
@emirkin
Copy link
Author

emirkin commented Apr 8, 2015

@gonzalo-bulnes , can I ask you 2 questions while I have your attention?

  1. How can I skip authentication (i.e. some equivalent of skip_before_filter :authenticate_account!)?
  2. How can I specify that I want the auth token parameter to be named "authentication_token" (as it was implemented in Devise before)? In my case, I specifically want to preserve backward compatibility.

Thanks much!

@gonzalo-bulnes gonzalo-bulnes added the question When closed, this issue will become part of the FAQ. label Apr 8, 2015
@gonzalo-bulnes
Copy link
Owner

Hi @emirkin,

All questions are welcome! That being said, I'd prefer to continue the discussion in the corresponding issues to keep one topic per issue, I give you the pointers here (and, by the way, I'll edit this issue title to make is easier to find):

  1. Yes, you can skip authentication using except and before options on your controllers. See Q: Using acts_as_token_authentication_handler_for in the base controller: how do I create exceptions? (R: :only/:except options are supported) #53
    Please note that the unless option is not supported as of v1.8.0 but will be soon (v1.9.0). I described, however, a workaround in Q: How do I do enable/disable token authentication depending on the controller reponse format? (R: The Rails Way!) #155 that you can use if you're in a hurry.
  2. There is no way for now to customize the param names specifically. (The names of the headers, on the contrary, can be customized through the header_names option. Here is the relevant code, see the difference between the token_header_name and the token_param_name methods for example.)

About backward compatibility with the deprecated Devise token authentication behaviour: please note that providing the user email (or any kind of identifier - see the identifiers option) is mandatory for security reasons (more in this gist). That was not part of the Devise strategy behaviour I think, so full backward compatibility is not possible anyway unless I'm wrong. It's for the better!

Regards!

@gonzalo-bulnes gonzalo-bulnes changed the title Getting NoAdapterAvailableError Q: Getting NoAdapterAvailableError? (R: Check the declarations order in your Gemfile!) Apr 8, 2015
gonzalo-bulnes referenced this issue in joel/simple_token_authentication Oct 27, 2015
gonzalo-bulnes added a commit that referenced this issue Nov 10, 2015
As a developer
In order to fix quickly trivial issues
I want the errors documentation to provide pointer to their most
probable cause

See #158 and #196
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question When closed, this issue will become part of the FAQ.
Projects
None yet
Development

No branches or pull requests

2 participants