Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"No route matches [GET] "/auth/google_oauth2" error keeps coming up

Error Message: "No route matches [GET] "/auth/google_oauth2"

View page link: <%= link_to "Log In with Google", "/auth/google_oauth2" %>

Relevant gems:

gem 'omniauth'
gem 'dotenv-rails'
gem 'omniauth-google-oauth2'

Initializer file:

Rails.application.config.middleware.use OmniAuth::Builder do
    provider :google_oauth2, ENV["GOOGLE_CLIENT_ID"],ENV["GOOGLE_CLIENT_SECRET"], skip_jwt: true
end

I'm using this as my guide: Medium Guide

I've gone through the process of setting up the app twice now on Developer Tools to get the Client ID and Secret in case that was the issue and both times I was getting the same error. I am new to coding so I'm sure this is something very silly and obvious, but I just can't seem to find it. Thank you for the help!

EDIT: I also have in my routes file: get '/auth/:provider/callback' => 'sessions#omniauth'

Rails Routes:

                               Prefix Verb   URI Pattern                                                                              Controller#Action
                                 root GET    /                                                                                        sessions#home
                                      GET    /auth/:provider/callback(.:format)                                                       sessions#omniauth
                               signup GET    /signup(.:format)                                                                        users#new
                                      POST   /signup(.:format)                                                                        users#create
                                login GET    /login(.:format)                                                                         sessions#new
                                      POST   /login(.:format)                                                                         sessions#create
                               logout DELETE /logout(.:format)                                                                        sessions#destroy
                          user_groups GET    /users/:user_id/groups(.:format)                                                         groups#index
                                      POST   /users/:user_id/groups(.:format)                                                         groups#create
                       new_user_group GET    /users/:user_id/groups/new(.:format)                                                     groups#new
                                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
                                      GET    /users(.:format)                                                                         users#index
                                      POST   /users(.:format)                                                                         users#create
                                      GET    /users/new(.:format)                                                                     users#new
                                      GET    /users/:id(.:format)                                                                     users#show
                           edit_group GET    /groups/:id/edit(.:format)                                                               groups#edit
                                group GET    /groups/:id(.:format)                                                                    groups#show
                                      DELETE /groups/:id(.:format)                                                                    groups#destroy
                           categories GET    /categories(.:format)                                                                    categories#index
                             category GET    /categories/:id(.:format)                                                                categories#show
                                cards GET    /cards(.:format)                                                                         cards#index
                                      POST   /cards(.:format)                                                                         cards#create
                             new_card GET    /cards/new(.:format)                                                                     cards#new
                            edit_card GET    /cards/:id/edit(.:format)                                                                cards#edit
                                 card GET    /cards/:id(.:format)                                                                     cards#show
                                      PATCH  /cards/:id(.:format)                                                                     cards#update
                                      PUT    /cards/:id(.:format)                                                                     cards#update
                                      DELETE /cards/:id(.:format)                                                                     cards#destroy
        rails_postmark_inbound_emails POST   /rails/action_mailbox/postmark/inbound_emails(.:format)                                  action_mailbox/ingresses/postmark/inbound_emails#create
           rails_relay_inbound_emails POST   /rails/action_mailbox/relay/inbound_emails(.:format)                                     action_mailbox/ingresses/relay/inbound_emails#create
        rails_sendgrid_inbound_emails POST   /rails/action_mailbox/sendgrid/inbound_emails(.:format)                                  action_mailbox/ingresses/sendgrid/inbound_emails#create
  rails_mandrill_inbound_health_check GET    /rails/action_mailbox/mandrill/inbound_emails(.:format)                                  action_mailbox/ingresses/mandrill/inbound_emails#health_check
        rails_mandrill_inbound_emails POST   /rails/action_mailbox/mandrill/inbound_emails(.:format)                                  action_mailbox/ingresses/mandrill/inbound_emails#create
         rails_mailgun_inbound_emails POST   /rails/action_mailbox/mailgun/inbound_emails/mime(.:format)                              action_mailbox/ingresses/mailgun/inbound_emails#create
       rails_conductor_inbound_emails GET    /rails/conductor/action_mailbox/inbound_emails(.:format)                                 rails/conductor/action_mailbox/inbound_emails#index
                                      POST   /rails/conductor/action_mailbox/inbound_emails(.:format)                                 rails/conductor/action_mailbox/inbound_emails#create
    new_rails_conductor_inbound_email GET    /rails/conductor/action_mailbox/inbound_emails/new(.:format)                             rails/conductor/action_mailbox/inbound_emails#new
   edit_rails_conductor_inbound_email GET    /rails/conductor/action_mailbox/inbound_emails/:id/edit(.:format)                        rails/conductor/action_mailbox/inbound_emails#edit
        rails_conductor_inbound_email GET    /rails/conductor/action_mailbox/inbound_emails/:id(.:format)                             rails/conductor/action_mailbox/inbound_emails#show
                                      PATCH  /rails/conductor/action_mailbox/inbound_emails/:id(.:format)                             rails/conductor/action_mailbox/inbound_emails#update
                                      PUT    /rails/conductor/action_mailbox/inbound_emails/:id(.:format)                             rails/conductor/action_mailbox/inbound_emails#update
                                      DELETE /rails/conductor/action_mailbox/inbound_emails/:id(.:format)                             rails/conductor/action_mailbox/inbound_emails#destroy
rails_conductor_inbound_email_reroute POST   /rails/conductor/action_mailbox/:inbound_email_id/reroute(.:format)                      rails/conductor/action_mailbox/reroutes#create
                   rails_service_blob GET    /rails/active_storage/blobs/:signed_id/*filename(.:format)                               active_storage/blobs#show
            rails_blob_representation GET    /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show
                   rails_disk_service GET    /rails/active_storage/disk/:encoded_key/*filename(.:format)                              active_storage/disk#show
            update_rails_disk_service PUT    /rails/active_storage/disk/:encoded_token(.:format)                                      active_storage/disk#update
                 rails_direct_uploads POST   /rails/active_storage/direct_uploads(.:format)                                           active_storage/direct_uploads#create
like image 676
BeccaN Avatar asked Jan 18 '21 23:01

BeccaN


1 Answers

Depending on the OmniAuth version (2.0.0):

OmniAuth now defaults to only POST as the allowed request_phase method

Add:

# Gemfile
gem 'omniauth-rails_csrf_protection', '~> 0.1'

Change Links to POST requests:

link_to "Log In with Google", "/auth/google_oauth2", method: :post
# or
button_to "Log In with Google", "/auth/google_oauth2"

If you still need GET requests, add knowing there is a security concern:

# config/initializers/omniauth.rb or similar
OmniAuth.config.allowed_request_methods = [:post, :get]

For omniauth < 2.0.0

Consider CVE remediation described here.

like image 140
Sarah Marie Avatar answered Sep 30 '22 14:09

Sarah Marie