簡體   English   中英

使用omniauth-google-oauth2進行身份驗證redirect_uri_mismatch

[英]Authenticating with omniauth-google-oauth2 redirect_uri_mismatch

好吧,很抱歉發布這樣一個a腳的問題,但是我設法在facebook,twitter甚至linkedin上使用了omniauth,但是我仍然無法在google omniauth 2.0上使用它,我發現問題與回調URI(我必須補充一點,我正在使用本地環境[localhost]進行測試,因此我嘗試通過以下方式更改URI

http:127.0.0.1:3000 / auth / google_oauth2 / callback /
http:127.0.0.1:3000 / auth / google_oauth2 /回調
https:127.0.0.1:3000 / auth / google_oauth2 / callback /
https:127.0.0.1:3000 / auth / google_oauth2 /回調
http:localhost:3000 / auth / google_oauth2 / callback /
http:本地主機:3000 / auth / google_oauth2 /回調*
https:localhost:3000 / auth / google_oauth2 / callback /
https:localhost:3000 / auth / google_oauth2 /回調

到目前為止,我已經分別嘗試了每個,但沒有一個起作用,看來標有*的是我瀏覽器中返回的那個,但仍然收到

The redirect URI in the request:
 http://localhost:3000/auth/google_oauth2/callback did not match a 
 registered redirect URI

因此,我正在尋找有關如何執行此身份驗證或如何為本地回調正確設置回調URI的答案。 提前致謝。

順便說一句:我正在使用Rails 4和omniauth,omniauth-google-oauth2 gems順便說一句:我刪除了“ //”,因此不會將它們視為鏈接

  • 另一個相關的問題是,如何在重定向列表中添加多個URI? 我嘗試將它們添加為用“,”分隔,或者只是用一個空格,因為沒有一個起作用,所以我真的不知道什么是正確的方法。

確保您使訪問類型在線

config.omniauth :google_oauth2, "[my key]", "[secret]", {access_type: 'online'}

我想你應該使用

http:// localhost:3000 / 用戶 / auth / google_oauth2 /回調

(您錯過了中間的用戶

該代碼對我有用。 在多個環境中使用Google Drive API。 您的“授權的重定向URIS”應如下所示(我使用的是google,您的可能是google_oauth2。更改了omniauth配置文件的提供程序選項)。 新行上的每個URI。

http://localhost:3000/auth/google/callback
https://staging_server/auth/google/callback
https://production_server/auth/google/callback

我的client_id,client_secret位於“ config / google_client.yml”中。 您在“ config / initializers”中的“ omniauth.rb”文件應如下

google_client =  YAML.load_file("#{Rails.root.join('config/google_client.yml')}")
ENV['GOOGLE_APP_NAME'] = google_client['APP_NAME']
ENV['GOOGLE_CLIENT_ID'] = google_client['CLIENT_ID']
ENV['GOOGLE_CLIENT_SECRET'] = google_client['CLIENT_SECRET']
ENV['GOOGLE_CLIENT_SCOPE'] = google_client['CLIENT_SCOPE']

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :google_oauth2, ENV["GOOGLE_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"],
    { name: "google",
      scope: ENV['GOOGLE_CLIENT_SCOPE'],
      prompt: "consent"
    }    
end

OmniAuth.config.on_failure = SomeController.action(:oauth_failure)

希望這對您有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM