错误消息:“没有路由匹配GET "/auth/google_oauth2”
查看页面链接:<%= link_to "Log In with Google", "/auth/google_oauth2" %>
相关宝石:
gem 'omniauth'
gem 'dotenv-rails'
gem 'omniauth-google-oauth2'初始化文件:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2, ENV["GOOGLE_CLIENT_ID"],ENV["GOOGLE_CLIENT_SECRET"], skip_jwt: true
end我用这个作为我的指南:介质指南
我已经经历了两次在开发工具上设置应用程序的过程,以获得客户端ID和机密,以防出现这种情况,而且两次我都收到了相同的错误。我对编码很陌生,所以我确信这是非常愚蠢和明显的事情,但我似乎找不到它。谢谢你的帮助!
编辑:我的路由文件中也有:get '/auth/:provider/callback' => 'sessions#omniauth'
铁路路线:
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发布于 2021-01-19 05:29:06
取决于OmniAuth版本(2.0.0):
OmniAuth现在默认为只将POST作为允许的request_phase方法。
添加
# Gemfile
gem 'omniauth-rails_csrf_protection', '~> 0.1'POST requests的更改链接
link_to "Log In with Google", "/auth/google_oauth2", method: :post
# or
button_to "Log In with Google", "/auth/google_oauth2"如果仍然需要GET 请求,请添加知道有 安全关切
# config/initializers/omniauth.rb or similar
OmniAuth.config.allowed_request_methods = [:post, :get]对杂食者< 2.0.0
考虑一下这里描述的CVE补救。
发布于 2021-08-11 17:49:54
OmniAuth现在默认为只发布允许的request_phase方法。
您需要将所有get请求更新为post请求。
在视图文件中,可以用表单替换锚标记并提交按钮。
<a href='/auth/developer'>Login with Developer</a>
以上代码可改为:
<%= form_tag('/auth/developer', method: 'post') do %>
<button type='submit'>Login with Developer</button>
<% end %>如果不想使用post方法,可以添加以下代码:
config/initializers/multiauth.rb
OmniAuth.config.allowed_request_methods = [:post, :get]
OmniAuth.config.silence_get_warning = true有关更多信息,请访问这里。
发布于 2021-07-04 11:23:10
我正经历着这个精确的错误,只不过它在我的主要布局上工作得很好,但是不工作在登陆页面布局上(我有两个不同的布局)。
信号链路
<%= link_to '/auth/google_oauth2', method: :post, :class => "btn-get-started font-weight-semibold" do %>
<span class="text-pink-400">
<i class="icon-cart2 mr-2"></i> Order
</span>
<% end %>链接方法显然是a :post,但是错误报告了丢失的get路由。
通过确保登陆页面布局有所有所需的javascripts来修正这个问题
<%= javascript_pack_tag 'application' %>https://stackoverflow.com/questions/65783394
复制相似问题