我该如何解决错误`未找到。用于Omniauth GitHub的身份验证密码?

问题描述 投票:0回答:1

我使用OmniAuth-Github实施了OmniAuth,但一直有效,直到无效为止。

我目前遇到以下错误:Not found. Authentication passthru.

伴随:

Started GET "/users/auth/github" for ::1 at 2020-01-02 14:25:49 +0800
Processing by Users::OmniauthCallbacksController#passthru as HTML
  Rendering text template
  Rendered text template (Duration: 0.0ms | Allocations: 2)
Completed 404 Not Found in 1ms (Views: 0.7ms | ActiveRecord: 0.0ms | Allocations: 548)

这是我的代码,也可以在这里查看:https://github.com/mirhamasala/lw_city_guide

# routes.rb

devise_for :users, controllers: { omniauth_callbacks: "users/omniauth_callbacks" }
# the routes

user_github_omniauth_authorize GET|POST /users/auth/github(.:format)
users/omniauth_callbacks#passthru

user_github_omniauth_callback GET|POST /users/auth/github/callback(.:format)
users/omniauth_callbacks#github
# devise.rb

config.omniauth :github, ENV['GITHUB_CLIENT_ID'], ENV['GITHUB_CLIENT_SECRET']
# controllers/users/omniauth_callbacks_controller.rb

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def github
    @user = User.from_omniauth(request.env["omniauth.auth"])

    if @user.persisted?
      sign_in_and_redirect @user, event: :authentication # This will throw if @user is not activated
      set_flash_message(:notice, :success, kind: "Github") if is_navigational_format?
    else
      session["devise.github_data"] = request.env["omniauth.auth"].except("extra")
      redirect_to new_user_registration_url
    end
  end

  def failure
    redirect_to root_path
  end
end
# user.rb

devise :database_authenticatable, :registerable,
:rememberable, :omniauthable, omniauth_providers: %i[github]

def self.from_omniauth(auth)
  where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
    user.email = auth.info.email
    user.password = Devise.friendly_token[0, 20]
    user.username = auth.info.nickname
    user.avatar = auth.info.image
    user.name = auth.info.name
    user.github_profile = auth.info.urls.GitHub
  end
end

有什么想法吗? 🧐

ruby-on-rails devise omniauth
1个回答
0
投票

问题似乎是宝石omniauth-rails_csrf_protection,我曾按照本指南来修复Rails中的OmniAuth漏洞:https://github.com/omniauth/omniauth/wiki/Resolving-CVE-2015-9284

卸载gem修复了错误。

© www.soinside.com 2019 - 2024. All rights reserved.