https://github.com/zquestz/authpointをテンプレートとしてgoogle oauth2 プロバイダーで omniauth を使用しています。アプリが認証後にホームページ (またはリダイレクト ページ) に移動するのではなく、ログイン ページに戻ることを除いて、すべて正常に動作します。この問題は、「nginx」で「thin」を使用した場合にのみ発生します。私の開発マシンでは、WEBrick サーバーで正常に動作します。
認証後、明示的にホームページにアクセスする (またはページをリロードする) と、アプリは正しくホームページに移動します。
関連するコードは次のとおりです。
# Get current provider
def current_user_id
session[:user_id]
end
# Setup the session if we have a valid user.
def setup_session(user_id)
session[:user_id] = user_id
end
# Store a url in the session that is safe to go back to (non-volatile)
def store_location
session[:return_to] = request.fullpath
end
# Redirect back to last good page, or the page you pass it if it doesn't know where to go.
def redirect_back_or_default(default)
location = session[:return_to] || default
location = default if location == request.fullpath
redirect_to(location)
session[:return_to] = nil
return
end
問題は、セッション ハッシュが、redirect_back_or_default の認証からのリダイレクト後に格納された変数の新しい値を取得しないため、'current_user_id' で :user_id を照会すると nil が返され、アプリがログイン ページに返されることです。
ActiveStore をセッション ストアとして使用しています。