Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails “没有与[GET]匹配的路由”/auth/google\u oauth2“错误不断出现_Ruby On Rails_Google Oauth_Omniauth - Fatal编程技术网

Ruby on rails “没有与[GET]匹配的路由”/auth/google\u oauth2“错误不断出现

Ruby on rails “没有与[GET]匹配的路由”/auth/google\u oauth2“错误不断出现,ruby-on-rails,google-oauth,omniauth,Ruby On Rails,Google Oauth,Omniauth,错误消息: 没有与[GET]/auth/google\u 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&quo

错误消息: 没有与[GET]/auth/google\u 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和密码,以防出现问题,而且两次都出现了相同的错误。我对编码是新手,所以我确信这是一件非常愚蠢和明显的事情,但我似乎找不到它。 谢谢你的帮助

编辑: 我的routes文件中还有: 获取“/auth/:provider/callback”=>“sessionsomniauth”

铁路路线:

                               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
根据OmniAuth 2.0.0版:

OmniAuth现在默认为仅POST作为允许的请求\u阶段方法

对于omniauth>=2.0.0 将链接更改为POST请求:

如果仍然需要GET请求,请添加“知道存在安全问题”:

对于omniauth<2.0.0 这里描述了修复

加:

然后,对于omniauth>=2.0.0,请按照上述步骤进行操作 根据OmniAuth 2.0.0版:

OmniAuth现在默认为仅POST作为允许的请求\u阶段方法

对于omniauth>=2.0.0 将链接更改为POST请求:

如果仍然需要GET请求,请添加“知道存在安全问题”:

对于omniauth<2.0.0 这里描述了修复

加:

然后,对于omniauth>=2.0.0,请按照上述步骤进行操作
您是否将get'/auth/:provider/callback'=>'sessionsomniauth'添加到config/routes.rb?routes.rb文件确定了在本例中/auth/google\u oauth2中,当有人访问您应用程序中的路径时会发生什么情况。错误是Rails在路由列表中找不到任何指示其操作的内容。感谢您的响应,是的,我确实有此功能在我的routes中,出现了相同的错误。我刚刚尝试使用GitHub登录来设置,但实际上我得到了相同的无路由匹配错误…是否还有其他原因可以这样做?我的omniauth版本?将路由信息添加到post。您能运行rails routes并将结果添加到您的问题中吗?添加到rails中将结果发送到我的帖子。另外,需要注意的是,我想,我刚刚用github设置了omniauth,这与“no route matches get”错误相同……您是否将get'/auth/:provider/callback'=>“sessionsomniauth”添加到config/routes.rb中?routes.rb文件确定了当有人访问您应用程序中的路径时,在他的case/auth/google_oauth2。错误是告诉你Rails在路由列表中找不到任何告诉它该做什么的东西。谢谢你的回复,是的,我的路由中确实有,这是相同的错误。我只是尝试使用GitHub登录来设置它,实际上我得到了同样的无路由匹配错误…是这样吗还有其他方法可以做到这一点吗?我的omniauth版本?将路由信息添加到帖子中。你能运行rails路由并将结果添加到你的问题中吗?将rails路由结果添加到我的帖子中。另外,需要注意的是,我想,我刚刚用github设置了omniauth,这与“no route matches get”错误相同。。.Yep,我可以复制原始问题并通过转换为POST来解决它。但是请注意,使用OmniAuth>2.0.0时,您还必须安装OmniAuth-rails\u csrf\u保护gem,链接CVE~>0.1中提到的版本不能完全与最新的OmniAuth版本配合使用。使用该版本,您会出现OmniAuth::AuthentityError错误改为使用“omniauth-rails\u csrf\u protection”,改为使用“~>1.0”。更新后的帖子使omniauth版本更加清晰。@SarahMarie似乎根据omniauth文档,即使omniauth>=2.0,仍然需要使用omniauth-rails\u csrf\u protection来防止csrf。我认为新的omniauth版本更改默认配置,以便不创建GET路由。但是CSRF的实际处理仍然在omniauth-rails\u CSRF\u Protection中完成。我如何知道我是否“仍然需要GET请求”?我有一个单独的Nuxt.js前端和Rails API,我的登录流程包括打开一个弹出窗口。打开一个URL,指向通向Omniauth端点/auth/google_oauth2的Rails路径。我没有看到在这种情况下使用POST的方法。有没有一种方法?或者是我需要得到的情况?是的,我能够重现原始问题并解决我的问题但请注意,在OmniAuth>2.0.0的情况下,您还必须安装OmniAuth-rails\u csrf\u保护gem,链接CVE~>0.1中提到的版本不能完全与最新的OmniAuth版本配合使用。使用该版本会出现OmniAuth::AuthentityError。相反,请使用“OmniAuth-rails\u csrf\u保护”、“~>1.0”`instead.Updated post使基于omniauth版本的内容更加清晰。@SarahMarie似乎根据omniauth文档,即使omniauth>=2.0,使用
omniauth-rails_csrf_保护仍然需要,以防止csrf。我认为新的omniauth版本更改了默认配置,因此不会创建GET路由。但是CSRF的实际处理仍然是在omniauth-rails\u CSRF\u Protection中完成的,我如何知道我是否“仍然需要GET请求”?我有一个单独的Nuxt.js前端和Rails API,我的登录流程包括打开一个弹出窗口。打开一个URL,指向指向Omniauth端点/auth/google_oauth2的Rails路由。在这种情况下,我看不到使用POST的方法。有吗?或者是我需要的情况?
link_to "Log In with Google", "/auth/google_oauth2", method: :post
# or
button_to link_to "Log In with Google", "/auth/google_oauth2"
# config/initializers/omniauth.rb or similar
OmniAuth.config.allowed_request_methods = [:post, :get]
# Gemfile
gem 'omniauth-rails_csrf_protection', '~> 0.1'