No route matches [POST] "/auth/auth0"

I’m following the tutorial below, but I get an error.

error:
No route matches [POST] “/auth/auth0”

version:

$ gem list | grep omniauth
omniauth (1.9.1)
omniauth-auth0 (1.4.2)
omniauth-oauth2 (1.3.1)
omniauth-rails_csrf_protection (0.1.2)

$ ruby -v
ruby 2.5.9p229 (2021-04-05 revision 67939) [x86_64-darwin21]

$ rails -v
Rails 4.2.11.3
<-- app/views/xxx/xxx.haml -->
= link_to 'Login', '/auth/auth0', method: :post
<-- config/initializers/auth0.rb -->

require 'omniauth'
require 'omniauth-auth0'

AUTH0_CONFIG = Rails.application.config_for(:auth0)

Rails.application.config.middleware.use OmniAuth::Builder do
  provider(
    :auth0,
    AUTH0_CONFIG['auth0_client_id'],
    AUTH0_CONFIG['auth0_client_secret'],
    AUTH0_CONFIG['auth0_domain'],
    callback_path: '/auth/auth0/callback',
    authorize_params: {
      scope: 'openid profile'
    }
  )
end
<-- config/routes.rb -->
  get '/auth/auth0/callback' => 'auth0#callback'
  get '/auth/failure' => 'auth0#failure'
  get '/auth/logout' => 'auth0#logout'

Please help!

Hi @kazuki.saito,

Welcome to the Auth0 Community!

I understand that you have encountered issues with logging in to your Application.

After testing this myself, I was able to successfully download the Ruby on Rails Quickstart, run the application, and log in.

When looking closely at your code snippet, I noticed that you are calling the link_to for login. Instead, have you tried using button_to to see if that works?

The button_to is what I am using in the Auth0 Ruby on Rails Quickstart.

I am looking forward to your reply.

Thank you.

Hi @rueben.tiow ,
Thank you for your reply!

I tried it with button_to, but it didn’t change.

<-- app/views/xxx/xxx.haml -->
= button_to 'Login', '/auth/auth0', method: :post

Hi @kazuki.saito,

Thank you for your update.

I have one other suggestion for you to try. Could you please try updating your omniauth libraries to the latest version?

Once you have updated the libraries, could you please retry logging in and see if you can log in successfully?

Thanks.

1 Like