railsのdeviseでgoogle認証を実装しました。
クロームでは普通にログイン、新規登録できるのですがios Safariだとログインをしようとするとトップページに戻ってしまいます。
何かわかる方は回答・コメントよろしくお願いいたします
2021-04-21T12:11:44.119932+00:00 app[web.1]: I, [2021-04-21T12:11:44.119842 #4] INFO -- : [7bacd3b9-281f-42ec-8347-9a4d11965349] Started GET "/serviceworker.js" for 162.158.118.168 at 2021-04-21 12:11:44 +0000 2021-04-21T12:11:47.189246+00:00 heroku[router]: at=info method=GET path="/users/auth/google_oauth2/callback?state=dec18365520b1a993f2731aaf690dbb7f214d6138be00c17&code=4%2F0AY0e-g6sU-28sYcFT0XMFNnFTdz3VjybKBGcBFDI9Qzt_0jVHad0mIDgiM7CXI-UMuMiuw&scope=email+profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+openid&authuser=0&prompt=none" host=ammot.net request_id=7e4414b5-bf10-41fe-a198-047145ae23d0 fwd="#" dyno=web.1 connect=0ms service=7ms status=302 bytes=747 protocol=https 2021-04-21T12:11:47.183531+00:00 app[web.1]: I, [2021-04-21T12:11:47.183449 #4] INFO -- : [7e4414b5-bf10-41fe-a198-047145ae23d0] Started GET "/users/auth/google_oauth2/callback?state=dec18365520b1a993f2731aaf690dbb7f214d6138be00c17&code=4%2F0AY0e-g6sU-28sYcFT0XMFNnFTdz3VjybKBGcBFDI9Qzt_0jVHad0mIDgiM7CXI-UMuMiuw&scope=email+profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+openid&authuser=0&prompt=none" for 162.158.118.198 at 2021-04-21 12:11:47 +0000 2021-04-21T12:11:47.185014+00:00 app[web.1]: D, [2021-04-21T12:11:47.184789 #4] DEBUG -- omniauth: (google_oauth2) Callback phase initiated. 2021-04-21T12:11:47.185421+00:00 app[web.1]: E, [2021-04-21T12:11:47.185141 #4] ERROR -- omniauth: (google_oauth2) Authentication failure! csrf_detected: OmniAuth::Strategies::OAuth2::CallbackError, csrf_detected | CSRF detected 2021-04-21T12:11:47.185929+00:00 app[web.1]: I, [2021-04-21T12:11:47.185869 #4] INFO -- : [7e4414b5-bf10-41fe-a198-047145ae23d0] Processing by Users::OmniauthCallbacksController#failure as HTML 2021-04-21T12:11:47.186003+00:00 app[web.1]: I, [2021-04-21T12:11:47.185944 #4] INFO -- : [7e4414b5-bf10-41fe-a198-047145ae23d0] Parameters: {"state"=>"##", "code"=>"##", "scope"=>"email profile https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile openid", "authuser"=>"0", "prompt"=>"none"} 2021-04-21T12:11:47.186605+00:00 app[web.1]: I, [2021-04-21T12:11:47.186554 #4] INFO -- : [7e4414b5-bf10-41fe-a198-047145ae23d0] Redirected to https://ammot.net/ 2021-04-21T12:11:47.186887+00:00 app[web.1]: I, [2021-04-21T12:11:47.186832 #4] INFO -- : [7e4414b5-bf10-41fe-a198-047145ae23d0] Completed 302 Found in 1ms (ActiveRecord: 0.0ms | Allocations: 117) 2021-04-21T12:11:49.810151+00:00 app[web.1]: I, [2021-04-21T12:11:49.810067 #4] INFO -- : [6a011301-6235-454b-82ef-f41ad88870e3] Started GET "/" for 162.158.118.198 at 2021-04-21 12:11:49 +0000 2021-04-21T12:11:49.812226+00:00 app[web.1]: I, [2021-04-21T12:11:49.812168 #4] INFO -- : [6a011301-6235-454b-82ef-f41ad88870e3]
omniauthcontroller
1class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController 2 3 # callback for google 4 def google_oauth2 5 callback_for(:google) 6 end 7 8 # common callback method 9 def callback_for(provider) 10 @user = User.from_omniauth(request.env["omniauth.auth"]) 11 if @user.persisted? 12 sign_in_and_redirect @user, event: :authentication #this will throw if @user is not activated 13 set_flash_message(:notice, :success, kind: "#{provider}".capitalize) if is_navigational_format? 14 else 15 session["devise.#{provider}_data"] = request.env["omniauth.auth"].except("extra") 16 redirect_to new_user_registration_url 17 end 18 end 19 20 def failure 21 redirect_to root_path 22 end 23end
applicationcontroller
1class ApplicationController < ActionController::Base 2 protect_from_forgery prepend: true 3end
deviserb
1config.omniauth :google_oauth2,ENV['GOOGLE_CLIENT_ID'],ENV['GOOGLE_CLIENT_SECRET'] 2#{:provider_ignores_state => true}も試しましたがダメでした
あなたの回答
tips
プレビュー