Windows 7 32ビットホストでVagrantとubuntu/trusty32というボックスを使用してRailsアプリを設定しています。アプリにはGoogle OAuthのログインがあります。 Gemfileには、それに対して次の宝石を持っている:omniauth-google-oauth2でログインできません。
gem 'omniauth'
gem 'omniauth-google-oauth2'
そして/config/initializers/devise.rb
中:私がログインしようとすると
config.omniauth :google_oauth2, ENV["GOOGLE_APP_ID"], ENV["GOOGLE_APP_SECRET"]
OmniAuth.config.full_host = lambda do |env|
forwarded = env['HTTP_X_FORWARDED_FOR']
forwarded.blank? ? "#{env['rack.url_scheme']}://#{env['HTTP_HOST']}" : "https://#{env['HTTP_HOST']}"
end
、それは「あなたがリダイレクトされる」とは何も次の起こっていない見て、このURLで停止します。
http://localhost:3000/omniauths/auth/google_oauth2/callback?state=xxxx&code=xxx
私は、次のログを得た:
Started GET "/omniauths/auth/google_oauth2" for 10.0.2.2 at 2017-10-07 11:07:21 +0000
log writing failed. closed stream
I, [2017-10-07T11:07:21.507524 #2581] INFO -- omniauth: (google_oauth2) Request phase initiated.
Started GET "/omniauths/auth/google_oauth2/callback?state=xxxx&code=xxxx" for 10.0.2.2 at 2017-10-07 11:07:21 +0000
log writing failed. closed stream
I, [2017-10-07T11:07:22.155462 #2581] INFO -- omniauth: (google_oauth2) Callback phase initiated.
Processing by SessionController#google_oauth2 as HTML
log writing failed. closed stream
Parameters: {"state"=>"a6a1e7b1733c564b96ab650f360fbae63cff5bdc6a488f1a", "code"=>"4/D4aX9Bm9XQmSIm_RXBhBi1EXE1AHKp3Q-WVbSpNSdvE"}
log writing failed. closed stream
Omniauth Load (4.5ms) SELECT `omniauths`.* FROM `omniauths` WHERE `omniauths`.`provider` = 'google_oauth2' AND `omniauths`.`uid` = '110281880098696358918' LIMIT 1
log writing failed. closed stream
Permission::Organization Load (1.6ms) SELECT `permission_organizations`.* FROM `permission_organizations` WHERE `permission_organizations`.`domain` = 'gmail.com' LIMIT 1
log writing failed. closed stream
Redirected to http://localhost:3000/
log writing failed. closed stream
Completed 403 Forbidden in 302ms (ActiveRecord: 17.4ms)
コードは私ではないと私はあまりにもルビーの専門家ではありません。だから私はなぜ私はその画面で立ち往生しているのか分かりません。ここで
class SessionController < Devise::OmniauthCallbacksController
def google_oauth2
@omniauth = Omniauth.find_for_google(request.env['omniauth.auth'])
if @omniauth&.persisted?
@omniauth.user.last_sign_in = Time.now
@omniauth.user.save
flash[:notice] = 'I signed in with Google authentication'
sign_in_and_redirect @omniauth, event: :authentication
else
#redirect_to new_user_registration_url, alert: @user.errors.full_messages.join("\n")
redirect_to '/', status: :forbidden
end
end
end
情報は、この問題のために十分に見えないconfig/routes.rb
Rails.application.routes.draw do
devise_for :omniauths, controllers: {
omniauth_callbacks: "session"
}
mount RailsAdmin::Engine => '/rails_admin', as: 'rails_admin'
post '/api', to: "api#post"
post '/error_catch', to: "api#error_catch"
post '/error_log', to: "api#error_log"
get '/file/:uuid/:filename', to: "api#file"
get '/svg_parts/*dxf_path', to: "svg#part"
post '/svg/project(.:format)'
post '/svg/requirement(.:format)'
get '/svg/test(.:format)'
get '/pdf/owner_estimate'
get '/pdf/builder_estimate'
get '/pdf/wholesale_estimate'
get '/api/perform_test'
get '/pdf/requirement'
root to: "angular#index"
get '/assets/*path', controller: 'application', action: 'handle_404'
get '*path', to: "angular#index"
end
です:私はまた、コントローラを見つけましたか?私は、さらに役立つ情報を提供することもできます。
はのは、試してみましょう。この=> '' 'devise_for:ユーザー、コントローラー:{omniauth_callbacks: "セッション"}' ''私は多分omniauthableないリソース上の誤り 'マッピングomniauth_callbacks(例外ArgumentError)' –
@RonanLouarnあなたのモデルの中で '' devise:omniauthable、omniauth_providers:[:google_oauth2] '' 'と書いていました@Sithu – Sithu
を得た –