简体   繁体   English

谷歌 OAuth 2.0 + Ruby on Rails 404:“未找到。 身份验证通道。”

[英]Google OAuth 2.0 + Ruby on Rails 404: “Not found. Authentication passthru.”

Below is the relevant code (do let me know if I'm missing anything.).以下是相关代码(如果我遗漏任何内容,请告诉我。)。

routes.rb:路线.rb:


devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }

devise_scope :user do 
    match '/sessions/user', to: 'devise/sessions#create', via: :post
    get '/join' => 'users/registrations#new'
end

resources :users do
    resources :video_lessons do
      resources :likes
    end
end

resources :users, only: [:show, :index]

devise.rb: devise.rb:

if Rails.env.production?
    config.omniauth :google_oauth2, ENV['GOOGLE_CLIENT_ID_PROD'[, ENV['GOOGLE_CLIENT_SECRET_PROD'], {}
else
    config.omniauth :google_oauth2, ENV['GOOGLE_CLIENT_ID_DEV'], ENV['GOOGLE_CLIENT_SECRET_DEV'], {}
end

omniauth_callbacks_controller.rb omniauth_callbacks_controller.rb

  def google_oauth2
    # You need to implement the method below in your model (e.g. app/models/user.rb)
    @user = User.from_omniauth(request.env['omniauth.auth'])

    if @user.persisted?
      flash[:notice] = I18n.t 'devise.omniauth_callbacks.success', kind: 'Google'
      sign_in_and_redirect @user, event: :authentication
    else
      session['devise.google_data'] = request.env['omniauth.auth'].except(:extra) # Removing extra as it can overflow some session stores
      redirect_to new_user_registration_url, alert: @user.errors.full_messages.join("\n")
    end
  end

devise/registrations/new.html.erb设计/注册/new.html.erb

<%= link_to "Sign up with Google", user_google_oauth2_omniauth_authorize_path %>

The authorized redirect URIs in my Developer's Console are: http://localhost:3000/users/auth/google_oauth2 and https://localhost:3000/users/auth/google_oauth2我的开发者控制台中的授权重定向 URI 是: http://localhost:3000/users/auth/google_oauth2https://localhost:3000/users/auth/google_oauth2

I've followed the docs ( https://github.com/zquestz/omniauth-google-oauth2 ) exactly, to no avail.我已经完全按照文档( https://github.com/zquestz/omniauth-google-oauth2 )进行操作,但无济于事。

Thank you for your help!谢谢您的帮助!

I recently got this working through this guide .我最近通过本指南得到了这个工作。 A more descriptive resource, and the source of the guide, is this official wiki example .更具描述性的资源和指南的来源是这个官方 wiki 示例

This commit shows all the files I changed to get google and github set up on my rails login page using the guide I mentioned first.提交显示了我使用我首先提到的指南在我的 rails 登录页面上设置的所有文件。

Just make sure when you use either of the guides, that you remove extra part of the data as it can overflow some session stores.只需确保在使用任一指南时删除额外的部分数据,因为它可能会溢出某些 session 存储。 The guides do not include this important piece of information.指南包含这一重要信息。 So in this line of omniauth_callbacks_controller.rb, your current code is correct :因此,在omniauth_callbacks_controller.rb 的这一行中,您当前的代码是正确的

...
    else
          session['devise.google_data'] = request.env['omniauth.auth'].except(:extra) # Removing extra as it can overflow some session stores
....

Good luck!祝你好运!

<%= link_to "Sign in with Google", user_google_oauth2_omniauth_authorize_path, method: :post %>

The request should be 'post'请求应该是“发布”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Rails google-oauth2 404 -“未找到。身份验证通路。” - Rails google-oauth2 404 - "Not found. Authentication passthru." 未找到。 身份验证直通。 (设计oauth facebook) - Not found. Authentication passthru. (devise oauth facebook) 设计/谷歌 OAuth 2:未找到。 认证通路 - Devise/Google OAuth 2: Not found. Authentication passthru 未找到。 身份验证直通。 stripe_connect和设计 - Not found. Authentication passthru. stripe_connect and Devise 设计、OmniAuth 和 Facebook:“未找到。身份验证通路。” - Devise, OmniAuth & Facebook: "Not found. Authentication passthru." 我该如何解决错误`未找到。 Omniauth GitHub 的身份验证通路。 - How can I solve the error `Not found. Authentication passthru.` for Omniauth GitHub? Rails 中的“未找到。身份验证直通 (Azure)” - "Not found. Authentication passthru(Azure)" in Rails Rails - Linkedin 身份验证:未找到。 身份验证通道 - Rails - Linkedin Auth: Not found. Authentication passthru “未找到。 身份验证passthru。“错误。 当它在另一个引擎内部时,Devise Omniauthable模块不起作用 - “Not found. Authentication passthru.” error. Devise Omniauthable module doesn't work when it's inside another engine Devise + OmniAuth Instagram:找不到。 认证通过 - Devise + OmniAuth Instagram: Not found. Authentication passthru
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM