AsteriskLabs / devise_google_authenticator

A Devise extension to allow your app to utilise Google's 2FA Mobile app
http://labs.asteriskinfosec.com.au/tag/devise_google_authenticator/
MIT License
216 stars 156 forks source link

No route matches {:action=>"show", :controller=>"displayqr"} #24

Closed carbonwallet closed 9 years ago

carbonwallet commented 10 years ago

I don't seem to have anything in the routes.rb for google authenticator. Should I have ?

Anyway when I signup (this is a new rails 4 app) I get the above error.

xntrik commented 10 years ago

Working on this issue at the moment. Need a clever way to get the correct respond_with dynamically back into the checkga controller. On 27 Mar 2014 21:32, "carbonwallet" notifications@github.com wrote:

I don't seem to have anything in the routes.rb for google authenticator. Should I have ?

Anyway when I signup (this is a new rails 4 app) I get the above error.

— Reply to this email directly or view it on GitHubhttps://github.com/AsteriskLabs/devise_google_authenticator/issues/24 .

carbonwallet commented 10 years ago

Great thanks.

xntrik commented 10 years ago

I've made a slight change to how some of the routes are dynamically generated.

This gem's routes are managed through devise, so you'll need to make sure that you've installed the devise gem first.

Can you give me the output of your rake routes command?

carbonwallet commented 10 years ago
rake routes
                  Prefix Verb   URI Pattern                    Controller#Action
                    root GET    /                              home#index
        new_user_session GET    /users/sign_in(.:format)       devise/sessions#new
            user_session POST   /users/sign_in(.:format)       devise/sessions#create
    destroy_user_session DELETE /users/sign_out(.:format)      devise/sessions#destroy
           user_password POST   /users/password(.:format)      devise/passwords#create
       new_user_password GET    /users/password/new(.:format)  devise/passwords#new
      edit_user_password GET    /users/password/edit(.:format) devise/passwords#edit
                         PATCH  /users/password(.:format)      devise/passwords#update
                         PUT    /users/password(.:format)      devise/passwords#update
cancel_user_registration GET    /users/cancel(.:format)        registrations#cancel
       user_registration POST   /users(.:format)               registrations#create
   new_user_registration GET    /users/sign_up(.:format)       registrations#new
  edit_user_registration GET    /users/edit(.:format)          registrations#edit
                         PATCH  /users(.:format)               registrations#update
                         PUT    /users(.:format)               registrations#update
                         DELETE /users(.:format)               registrations#destroy
          user_displayqr GET    /users/displayqr(.:format)     devise/displayqr#show
                         PATCH  /users/displayqr(.:format)     devise/displayqr#update
                         PUT    /users/displayqr(.:format)     devise/displayqr#update
            user_checkga GET    /users/checkga(.:format)       devise/checkga#show
                         PATCH  /users/checkga(.:format)       devise/checkga#update
                         PUT    /users/checkga(.:format)       devise/checkga#update
                   users GET    /users(.:format)               users#index
                         POST   /users(.:format)               users#create
                new_user GET    /users/new(.:format)           users#new
               edit_user GET    /users/:id/edit(.:format)      users#edit
                    user GET    /users/:id(.:format)           users#show
                         PATCH  /users/:id(.:format)           users#update
                         PUT    /users/:id(.:format)           users#update
                         DELETE /users/:id(.:format)           users#destroy
xntrik commented 10 years ago

I've recently made a change that more gracefully determines how to respond_with after the user successfully enters their password. From version 0.3.11 this is in place, although the current version is 0.3.13.

Can you give it a shot with this updated gem and let me know if the error persists?

carbonwallet commented 10 years ago

I'm using GEM 0.3.13 and I still get the same error.

It's reproducible from a fresh rails install. i..e

rails new newapp -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb

Then add the authenticator gem and try to register.

allcentury commented 10 years ago

I'm also getting the same error

ActionController::UrlGenerationError at /users
No route matches {:action=>"show", :controller=>"devise_invitable/displayqr"}
zdraganov commented 10 years ago

What happens on this one? Some progress?

xntrik commented 10 years ago

Sorry for the delay in this, will check the failed condition as per @carbonwallet's instructions above.

joshrendek commented 10 years ago

I actually run into this when I specify a registration controller in my routes:

  devise_for :users, :controllers => { :registrations => "registrations" }

Any ideas? As a side note I'm trying to redirect to a certain path after sign up but displayqr seems to be hijacking that.

xntrik commented 10 years ago

Hi @joshrendek - the hijacking of the registration controller is also what devise_google_authenticator does. So you're probably running into a race condition after sign-up. I think I'll add a configurable option to enable/disable the displayqr page after sign-up. This way, you can configure this to disable, and therefore users won't be redirected to displayqr during sign-up, and the only way they can enable QR is if they visit the displayqr page.

joshrendek commented 10 years ago

@xntrik can you tell me where to look so i can monkey patch this for now? I wasn't able to find anything digging through the source :(

xntrik commented 10 years ago

I'm still not entirely sure how to recreate this issue, but, I have a feeling it either relates to custom devise controllers (as in @joshrendek's situation) or something else? With the current master gem (which I am close to releasing as version 0.3.15), following these steps I'm not getting this issue. This is with ruby 2.0.0-p481 and rails 4.1.5.

Execute:

rails new testapp
cd testapp
vi Gemfile # or edit with whatever text editor you like

add:

gem 'devise'
gem 'devise_google_authenticator'

Then re-bundle and install devise and devise_google_authenticator, and configure it for the 'user' model

bundle
rails g devise:install
rails g devise user
rails g devise_google_authenticator:install
rails g devise_google_authenticator user

We then have to edit the app to use devise.

vi app/controllers/application_controller.rb

Add just before the end of the class

before_filter :authenticate_user!

Edit the routes file

vi config/routes.rb

Set a root. The only routes in here now should be devise_for :users, and whatever root you set

root 'home#index'

Create the home controller

vi app/controllers/home_controller.rb

Put something like this in there:

class HomeController < ApplicationController
  def index
  end
end

Create the home view

mkdir app/views/home
vi app/views/home/index.html.erb

Create a simple view:

Welcome home

Migrate the database

rake db:migrate

Then start the server

rails s

Now, when you visit http://localhost:3000 you'll be forwarded to the sign-in page, if you click 'sign-up', and enter an email and password twice, you should end up at http://localhost:3000/users/displayqr.

The output of rake routes should look like:

                  Prefix Verb   URI Pattern                        Controller#Action
        new_user_session GET    /users/sign_in(.:format)           devise/sessions#new
            user_session POST   /users/sign_in(.:format)           devise/sessions#create
    destroy_user_session DELETE /users/sign_out(.:format)          devise/sessions#destroy
           user_password POST   /users/password(.:format)          devise/passwords#create
       new_user_password GET    /users/password/new(.:format)      devise/passwords#new
      edit_user_password GET    /users/password/edit(.:format)     devise/passwords#edit
                         PATCH  /users/password(.:format)          devise/passwords#update
                         PUT    /users/password(.:format)          devise/passwords#update
cancel_user_registration GET    /users/cancel(.:format)            devise/registrations#cancel
       user_registration POST   /users(.:format)                   devise/registrations#create
   new_user_registration GET    /users/sign_up(.:format)           devise/registrations#new
  edit_user_registration GET    /users/edit(.:format)              devise/registrations#edit
                         PATCH  /users(.:format)                   devise/registrations#update
                         PUT    /users(.:format)                   devise/registrations#update
                         DELETE /users(.:format)                   devise/registrations#destroy
  refresh_user_displayqr POST   /users/displayqr/refresh(.:format) devise/displayqr#refresh
          user_displayqr GET    /users/displayqr(.:format)         devise/displayqr#show
                         PATCH  /users/displayqr(.:format)         devise/displayqr#update
                         PUT    /users/displayqr(.:format)         devise/displayqr#update
            user_checkga GET    /users/checkga(.:format)           devise/checkga#show
                         PATCH  /users/checkga(.:format)           devise/checkga#update
                         PUT    /users/checkga(.:format)           devise/checkga#update
                    root GET    /                                  home#index

If you don't want to redirect to the users/displayqr page after sign-up, you can uncomment the config.ga_bypass_signup option in config/initializers/devise.rb.

I'm keen to try and squash this bug - and I hope the above helps.

xntrik commented 10 years ago

Haha, sorry @joshrendek - just pushed up to the repo now. But, you can see the changes in https://github.com/AsteriskLabs/devise_google_authenticator/commit/d0de66079a83dbcaaad73364306821724e6c07f6

joshrendek commented 10 years ago

Awesome its working :)

f3ndot commented 10 years ago

So I assume that this issue is now closed (or should be :wink: )?

xntrik commented 10 years ago

Hi @f3ndot - I'm half waiting on whether @carbonwallet, @allcentury or @zdraganov are still having issues.

allcentury commented 10 years ago

working for me now - thanks @xntrik

xntrik commented 9 years ago

I'm going to close this - but - if anyone sees these errors this can be re-opened.