简体   繁体   English

Facebook,LinkedIn和Google的Oauth2登录已停止使用Devise和Omniauth,但仍适用于LinkedIn和Twitter

[英]Oauth2 Login for Facebook, Linkedin and Google Stopped Working with Devise and Omniauth, But Still Works for LinkedIn and Twitter

I have a site that is configured to work with multiple Oauth2 API's using Devise with Omniauth and has been functioning normally until last week. 我有一个站点,该站点配置为通过Devise和Omniauth与多个Oauth2 API一起使用,并且一直可以正常运行,直到上周为止。 Currently login with Twitter and Github still function normally; 目前使用Twitter和Github登录仍然可以正常使用; however, Facebook, LinkedIn and Google are giving me an error stating that the Redirect URI doesn't match. 但是,Facebook,LinkedIn和Google给我一个错误,指出重定向URI不匹配。 The Error Messages read: 错误消息显示为:

Facebook: Facebook的:

ERROR -- omniauth: (facebook) Authentication failure! 错误-omniauth:(facebook)身份验证失败! invalid_credentials: >OAuth2::Error, : {"error":{"message":"Error validating verification code. Please make sure your >redirect_uri is identical to the one you used in the OAuth dialog request","type":"OAuthException","code":100,"fbtrace_id":"XXXXXXXXXX"}} invalid_credentials:> OAuth2 :: Error,:{“错误”:{“消息”:“验证验证码时出错。请确保您的> redirect_uri与您在OAuth对话框请求中使用的代码相同”,“类型”:“ OAuthException”, “代码”:100, “fbtrace_id”: “XXXXXXXXXX”}}

LinkedIn: LinkedIn:

ERROR -- omniauth: (linkedin) Authentication failure! 错误-omniauth:(linkedin)身份验证失败! invalid_credentials: >OAuth2::Error, invalid_request: missing required parameters, includes an invalid parameter value, parameter more than once. invalid_credentials:> OAuth2 :: Error,invalid_request:缺少必需的参数,包括无效的参数值,参数多次。 : Unable to retrieve access token : appId or redirect uri does not match authorization code or authorization code expired {"error_description":"missing required parameters, includes an invalid parameter value, parameter more than once. : Unable to retrieve access token : appId or redirect uri does not match authorization code or authorization code expired","error":"invalid_request"} :无法检索访问令牌:appId或重定向uri与授权代码不匹配或授权代码已过期{“ error_description”:“缺少必需的参数,包含无效的参数值,参数多次。。:无法检索访问令牌:appId或重定向uri与授权码不匹配或授权码已过期“,”错误“:” invalid_request“}

Google 谷歌

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

I went reviewed the requests that were sent for all three of these in the Chrome Developers Console and the redirect uri for the callback matches the uri that is registered with each API (Which has not changed since it was working). 我在Chrome开发者控制台中查看了针对所有这三个请求发送的请求,并且回调的重定向uri与在每个API中注册的uri匹配(自从工作以来,它没有变化)。

The challenge with back tracking this error is I am not 100% sure when these stopped working as I was logging in directly or using the Github login during recent integration tests as I installed new functionality. 回溯跟踪此错误的挑战在于,当我安装新功能时,当我直接登录或在最近的集成测试期间使用Github登录名时,这些错误停止了工作时,我还不确定100%。 (Big Lesson Learned!) One of the significant changes that could be impacting this is that I integrated the Traceable extension for Devise which had me require the Warden Gem. (汲取了很多教训!)可能会影响这一变化的重大变化之一是,我集成了Devise的Traceable扩展,使我需要Warden Gem。 However, I removed both the Traceable and Warden configuration and restored the user model and config files to their previous state and I am having the same issue. 但是,我同时删除了Traceable和Warden配置,并将用户模型和配置文件恢复到它们以前的状态,并且遇到了同样的问题。

I would generally prefer to provide more code samples but to be honest, I am not sure what code to start with. 我通常希望提供更多的代码示例,但老实说,我不确定该以什么代码开头。 I am hoping that someone has experienced a similar problem and can point in the right direction to start. 我希望有人遇到过类似的问题,并且可以指出正确的方向开始。

To Start, below is my Devise Initializer with Comments Removed to Shorten 首先,下面是我的Devise Initializer,删除了注释以缩短

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

The omniauth.yml file that is loaded looks like this: 加载的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" }

I had exactly similar issue, facebook working, linkedin and google - not. 我遇到了完全类似的问题,facebook工作,linkedin和google-没有。

After some digging/googling i was able to fix my issue by downgrading: 经过一些挖掘/搜索后,我能够通过降级来解决我的问题:

gem 'omniauth-oauth2', '1.3.1'

So my Gemfile looks like: 所以我的Gemfile看起来像:

gem 'devise'
gem 'koala'
gem 'omniauth-oauth2', '1.3.1'
gem 'omniauth-facebook'
gem 'omniauth-google-oauth2'
gem 'omniauth-linkedin-oauth2'

我经历并更新了所有Omniauth Gems,因为最近有版本修订,并且所有问题都已解决。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM