簡體   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

我有一個站點,該站點配置為通過Devise和Omniauth與多個Oauth2 API一起使用,並且一直可以正常運行,直到上周為止。 目前使用Twitter和Github登錄仍然可以正常使用; 但是,Facebook,LinkedIn和Google給我一個錯誤,指出重定向URI不匹配。 錯誤消息顯示為:

Facebook的:

錯誤-omniauth:(facebook)身份驗證失敗! invalid_credentials:> OAuth2 :: Error,:{“錯誤”:{“消息”:“驗證驗證碼時出錯。請確保您的> 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 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

加載的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" }

我遇到了完全類似的問題,facebook工作,linkedin和google-沒有。

經過一些挖掘/搜索后,我能夠通過降級來解決我的問題:

gem 'omniauth-oauth2', '1.3.1'

所以我的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