Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActionDispatch::Cookies::CookieOverflow in Users::OmniauthCallbacksController#google_oauth2 #1038

Open
AxelBriche opened this issue Mar 4, 2021 · 2 comments

Comments

@AxelBriche
Copy link

AxelBriche commented Mar 4, 2021

Configuration

  • Provider Gem: omniauth-google_oauth2
  • Ruby Version: 3.0.0
  • Framework: Ruby on Rails 6.1.2.1
  • Platform: MacOs

Actual Behavior

ActionDispatch::Cookies::CookieOverflow in Users::OmniauthCallbacksController#google_oauth2

Capture d’écran 2021-03-04 à 23 06 21

Line:
session["devise.google_oauth2_data"] = request.env["omniauth.auth"].except(:extra) # Removing extra as it can overflow some session stores

Controller:

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  # See https://github.com/omniauth/omniauth/wiki/FAQ#rails-session-is-clobbered-after-callback-on-developer-strategy
  skip_before_action :verify_authenticity_token, only: :google_oauth2

  def google_oauth2
    @user = User.from_omniauth(request.env["omniauth.auth"])

    if @user.persisted?
      sign_in_and_redirect @user, event: :authentication # this will throw if @user is not activated
      set_flash_message(:notice, :success, kind: "Google") if is_navigational_format?
    else
      session["devise.google_oauth2_data"] = request.env["omniauth.auth"].except(:extra) # Removing extra as it can overflow some session stores
      redirect_to new_user_registration_url
    end
  end

  def failure
    redirect_to root_path
  end
end

The scope for google inside the devise config file:
scope: 'userinfo.email,userinfo.profile'

@AxelBriche
Copy link
Author

AxelBriche commented Mar 4, 2021

If I add except!(:extra) instead of except(:extra) the problem is solved.
It's an error inside the documentation ?

@rodolfobandeira
Copy link

An alternative for this issue is to switch your cookies (max 4kb capacity) to https://github.com/rails/activerecord-session_store which provides a key/value storage directly in your db

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants