AsteriskLabs/devise_google_authenticator

Use with Active Admin

toreym opened this issue · 10 comments

I'm getting a route not found error when using Active Admin. I was able to get it to work by changing this line. But not sure the best way to fix it.

# respond_with resource, :location => { :controller => 'checkga', :action => 'show', :id => tmpid}
redirect_to "/admin/checkga?id=#{tmpid}"

Hi Torey, can you elaborate on the Active Admin ? Keen to figure out why this isn't working for you. (Can you also shoot me a copy of your rake routes output?)

cp commented

Yeah, I seem to be getting this as well.

Did anything come of this issue ?

I'm sorry I've kept the fix/workaround I had above. But haven't had time to research a proper fix.

It appears that in this instance the devise routes are underneath active_admin/devise instead of just devise.

Unfortunately, the above fix looks like the quickest patch at this point in time, until I can at least figure out how dynamically add the routes for devise_google_authenticator under active_admin/devise instead of just devise/

I am trying to do the same but I had no luck. Where I should put this fix?
I tried to make a route like

get 'active_admin/admin/checkga', to: 'active_admin/devise/checkga#show'

but I get a 「Unable to autoload constant ActiveAdmin::Devise::CheckgaController, expected /Users/interbooks04/Documents/Aptana Studio 3 Workspace/ib-global/app/controllers/active_admin/devise/checkga_controller.rb to define it」error.

ok I fixed in an alternative way.
in routes.rb
get 'admin/checkga', to: 'active_admin/devise/checkga#show'
and copied the checkga_controller.rb from the source code to /controllers/devise/checkga_controller.rb without modifying anything (only the redirect path after login to admin_root_path)

Hi All, I've made a minor change to the checkga path where it more dynamically determines where to redirect the user after they've authenticated, prior to the Google Token being checked.

I've tested this with Rails 4.0.4 and Active Admin 1.0.0.pre.

To make this work I performed the following steps
rails new aatest # generate a new rails app called aatest
added gem 'activeadmin', github: 'gregbell/active_admin' into the Gemfile
added gem 'devise_google_authenticator', '0.3.11' into the Gemfile
bundle # update the gems
rails g active_admin:install # installs the active admin capability
rake db:migrate # migrate these db changes
rails g devise_google_authenticator:install # installs this gem
rails g devise_google_authenticator AdminUser # modifies the Active Admin default user for google auth capability
rake db:migrate # migrate the google auth db changes
rails c # logs into the rails console (we need to set default secrets for the users)

AdminUser.where(:gauth_secret => nil).each do |user|
user.send(:assign_auth_secret)
user.save
end
exit

added root 'admin/dashboard#index' into routes.rb # need a root route
modified devise.google_authenticator.en.yml in config/locales such that checkga: and displayqr: i2n settings where for admin_user instead of user

rails s # starts the rails server

Logged into the app
Visited /admin/displayqr to enrole and enable QR

Voila ..

I hope this works for you guys!

Closing for the moment, but, feel free to open again if it remains broken.

Hi , I have installed gem 'devise_google_authenticator' in rails 5.2.1 but i got error i.e,Gem Load Error is: undefined method `to_prepare' for ActionDispatch::Callbacks:Class
Did you mean? to_param , please give me suggestion