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

request.env['omniauth.auth'] is return nil #326

Closed
rpjuvvadi opened this issue May 24, 2018 · 2 comments
Closed

request.env['omniauth.auth'] is return nil #326

rpjuvvadi opened this issue May 24, 2018 · 2 comments

Comments

@rpjuvvadi
Copy link

rpjuvvadi commented May 24, 2018

Hi,

I'm trying to add/modify scope & callback_path dynamically using Omniauth Setup Phase.
I am able to do OAuth. But, request.env["omniauth.auth"] is returning nil in Callback.

I launch the OAuth process using /google_auth_callbacks/gmail_auth instead of /auth/google_oauth2

Here's my config,

omniauth.rb

# config/initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
  provider :google_oauth2, Figaro.env.google_client_id, Figaro.env.google_client_secret, setup: true
end
OmniAuth.config.on_failure = GoogleAuthCallbacksController.action(:failure)

routes.rb

..
..
get 'auth/google_oauth2/setup' => 'google_auth_callbacks#setup'
..

google_auth_callbacks_controller.rb

class GoogleAuthCallbacksController < ApplicationController
  def gmail_auth
    session[:google_auth_scopes] = [ 'https://mail.google.com/', 'userinfo.profile', 'userinfo.email' ]
    session[:google_auth_callback] = "/google_auth_callbacks/gmail_success"
    redirect_to '/auth/google_oauth2'
  end

  def setup
    request.env["omniauth.strategy"].options[:scope]         = session[:google_auth_scopes]
    request.env["omniauth.strategy"].options[:callback_path] = session[:google_auth_callback]
    render plain: "Setup Completed", status: 404
  end


  def gmail_success
    integration = GmailIntegration.where(user_id: current_user.id, flow: :in).first_or_initialize
    auth =  request.env['omniauth.auth'] # here, auth = nil everytime
    .....
  end

end

Gemfile.lock

rails (5.1.4)
omniauth (1.8.1)
omniauth-oauth2 (1.0.2)
omniauth-google-oauth2 (0.2.2)

Help?

@rpjuvvadi
Copy link
Author

rpjuvvadi commented May 24, 2018

If it helps,

request.env["action_dispatch.request.unsigned_session_cookie"]

{ "session_id"=>"18f16f976d873bf19cf542e9cd0fe8e7",
  "warden.user.user.key"=>[ ["<SOME_UUID>"],  "$2a$11$QClBu2yQVxCRk5E88NCs7."],
  "_csrf_token"=>"<CSRF_TOKEN>",
  "google_auth_scopes"=>["https://mail.google.com/", "userinfo.profile", "userinfo.email"],
  "google_auth_callback"=>"/google_auth_callbacks/gmail_success",
  "omniauth.params"=>{}}

@rpjuvvadi rpjuvvadi changed the title Dynamic Scopes using Setup Phase request.env['omniauth.auth'] is return nil May 24, 2018
@zquestz
Copy link
Owner

zquestz commented Dec 8, 2018

I would highly recommend using the default url for auth. Renaming has presented issues for many users. Please test using google_oauth2 and see if the issue persists.

@zquestz zquestz closed this as completed Dec 8, 2018
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