Oauth2登录Facebook,Linkedin和谷歌停止与Devise和Omniauth合作,但仍适用于LinkedIn和Twitter

Dav*_*Uli 2 ruby-on-rails devise omniauth-facebook omniauth-linkedin google-oauth2

我有一个站点,配置为使用Devise与Omniauth一起使用多个Oauth2 API,并且一直运行到上周.目前登录Twitter和Github仍然正常运行; 然而,Facebook,LinkedIn和谷歌给我一个错误,指出重定向URI不匹配.错误消息读取:

Facebook的:

错误 - omniauth:(facebook)身份验证失败!invalid_credentials:> OAuth2 ::错误,:{"error":{"message":"验证验证码时出错.请确保您的> redirect_uri与您在OAuth对话框请求中使用的相同","输入":" OAuthException", "代码":100, "fbtrace_id": "XXXXXXXXXX"}}

LinkedIn:

错误 - omniauth:(linkedin)身份验证失败!invalid_credentials:> OAuth2 :: Error,invalid_request:缺少必需参数,包含无效参数值,参数多次.:无法检索访问令牌:appId或重定向uri与授权代码或授权代码过期不匹配{"error_description":"缺少必需参数,包含无效参数值,参数多次.:无法检索访问令牌:appId或重定向uri与授权代码或授权代码过期不匹配","错误":"invalid_request"}

谷歌

错误 - omniauth:(google_oauth2)身份验证失败!invalid_credentials:> OAuth2 :: Error,redirect_uri_mismatch:{"error":"redirect_uri_mismatch"}

我查看了Chrome开发者控制台中针对所有这三个请求发送的请求,并且回调的重定向uri与每个API注册的uri相匹配(自从它工作以来没有更改).

回溯跟踪此错误的挑战是,当我安装新功能时,由于我在最近的集成测试期间直接登录或使用Github登录,因此我不能100%确定这些错误.(大课程学到了!)可能影响这一点的重大变化之一就是我整合了Devise的Traceable扩展,我需要Warden Gem.但是,我删除了Traceable和Warden配置,并将用户模型和配置文件恢复到以前的状态,我遇到了同样的问题.

我通常更愿意提供更多的代码示例,但说实话,我不确定从哪个代码开始.我希望有人遇到类似的问题,并指出正确的方向开始.

要开始,下面是我的Devise初始化程序,注释已删除以缩短

Devise.setup do |config|

  config.mailer_sender = 'no-reply@' + ENV['DOMAIN_NAME']

  config.mailer = 'Devise::Mailer'

  require 'devise/orm/active_record'

  config.case_insensitive_keys = [:email]

  config.strip_whitespace_keys = [:email]

  config.skip_session_storage = [:http_auth]

  config.stretches = Rails.env.test? ? 1 : 10

  config.allow_unconfirmed_access_for = 10.days

  config.reconfirmable = true

  config.confirmation_keys = [:email]

  config.remember_for = 2.weeks

  config.expire_all_remember_me_on_sign_out = true

  config.password_length = 8..72

  config.email_regexp = /\A[^@]+@[^@]+\z/

  config.reset_password_keys = [:email]

  config.reset_password_within = 6.hours

  config.sign_in_after_reset_password = true

  config.sign_out_via = :get

  # ==> OmniAuth
  # Add a new OmniAuth provider. Check the wiki for more information on setting
  # up on your models and hooks.
  # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'

  require "omniauth-google-oauth2" # Added Based on Response to Another Stackoverflow Issues - Did Not Help.

  OMNIAUTH = YAML.load(File.read(File.expand_path('../../omniauth.yml', __FILE__))).deep_symbolize_keys

  OMNIAUTH.each_value do |provider|
    config.omniauth provider[:reference].to_sym, ENV[provider[:key_ref]], ENV[provider[:secret_ref]], { :scope => provider[:scope] }
  end
end
Run Code Online (Sandbox Code Playgroud)

加载的omniauth.yml文件如下所示:

facebook: { reference: "facebook",
            name: "Facebook",
            scope: "email, public_profile, user_birthday",
            key_ref: "FACEBOOK_KEY",
            secret_ref: "FACEBOOK_SECRET" }

twitter:  { reference: "twitter",
            name: "Twitter",
            scope: "r_fullprofile, r_emailaddress",
            key_ref: "TWITTER_KEY",
            secret_ref: "TWITTER_SECRET" }

linkedin: { reference: "linkedin",
            name: "LinkedIn",
            scope: "r_basicprofile r_emailaddress",
            key_ref: "LINKEDIN_KEY",
            secret_ref: "LINKEDIN_SECRET" }

github: {   reference: "github",
            name: "GitHub",
            scope: "user, public_repo",
            key_ref: "GITHUB_KEY",
            secret_ref: "GITHUB_SECRET" }

google:   { reference: "google_oauth2",
            name: "Google",
            scope: "email, profile",
            key_ref: "GOOGLE_KEY",
            secret_ref: "GOOGLE_SECRET" }
Run Code Online (Sandbox Code Playgroud)

ale*_*cat 6

我有类似的问题,Facebook工作,linkedin和谷歌 - 没有.

经过一些挖掘/谷歌搜索,我能够通过降级来解决我的问题:

gem 'omniauth-oauth2', '1.3.1'
Run Code Online (Sandbox Code Playgroud)

所以我的Gemfile看起来像:

gem 'devise'
gem 'koala'
gem 'omniauth-oauth2', '1.3.1'
gem 'omniauth-facebook'
gem 'omniauth-google-oauth2'
gem 'omniauth-linkedin-oauth2'
Run Code Online (Sandbox Code Playgroud)