我想與谷歌oauth2使用devise和omniauth進行身份驗證。我按照omniauth文檔中的規定建立了宗教信仰的回電,並且甚至使用相同的確切代碼。 https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview谷歌oauth失敗與401未經授權在rails omniauth
我上傳的代碼github上:https://github.com/kiranjulapalli/devisetest
我重定向到登錄,當我選擇我的帳戶,我重定向再次sign_in頁。我在這裏錯過了什麼?
這裏是日誌:
Started GET "https://stackoverflow.com/users/auth/google_oauth2/callback?state=3baa394efe9c586b30fgfc05b1f618af04b7728d0d75c3c1&code=4/HxV9O
37jKYgxg10EWDntdfewZTz3.4kqevOMEweMTshQV0ieZDArQUdYefAI" for 127.0.0.1 at 2013-04-15 16:36:01 -0400
Processing by Users::OmniauthCallbacksController#google_oauth2 as HTML
Parameters: {"state"=>"3baa394efe9c586b30fgfc05b1f618af04b7728d0d75c3c1", "code"=>"4/HxV9O
37jKYgxg10EWDntdfewZTz3.4kqevOMEweMTshQV0ieZDArQUdYefAI"}
MOPED: 127.0.0.1:27017 COMMAND database=admin command={:ismaster=>1} (2.0001ms)
MOPED: 127.0.0.1:27017 QUERY database=devisetest_development collection=users selector={"$query"=>{"email"
=>"[email protected]"}, "$orderby"=>{:_id=>1}} flags=[:slave_ok] limit=-1 skip=0 batch_size=nil fields=nil
(0.9999ms)
Completed 401 Unauthorized in 24ms
#custom log statements
logger::Find if this user exists
logger::Return user
logger:Got call back
logger:User persisted
我的routes.rb文件:
Devisetest::Application.routes.draw do
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
resources :users
root :to => 'home#index'
end
謝謝,我有這個'<%flash.each do | name,msg | %> <%content_tag:div,msg,id:「flash _#{name}」%> <% end %>'在application.html.erb中。是不是打印flash通知和警報? – Kiran
如果你這樣做: '<%= content_tag:div,msg,id:「flash _#{name}」%> 您忘記了=。 –
啊,這解釋..謝謝。我正在嘗試設計skip_confirmable! – Kiran