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 nil in Omniauth Callback #1057

Open
alec-c4 opened this issue Feb 19, 2022 · 6 comments
Open

request.env['omniauth.auth'] is nil in Omniauth Callback #1057

alec-c4 opened this issue Feb 19, 2022 · 6 comments

Comments

@alec-c4
Copy link

alec-c4 commented Feb 19, 2022

Configuration

  • Provider Gem: omniauth-google-oauth2, omniauth-facebook, omniauth-vkontakte
  • Ruby Version: 3.0.2
  • Framework: ruby on rails 6.1.4.1
  • Platform: macOS

Expected Behavior

It should allow to login using Google, Facebook, and Vk

Actual Behavior

Exception NoMethodError undefined method `provider' for nil:NilClass and request.env['omniauth.auth'] is nil in OmniauthCallbackController

Steps to Reproduce

Create app from any rails template https://github.com/alec-c4/kickstart for example

rails new test_application --no-skip-hotwire -T -c bootstrap -j esbuild -d postgresql -m https://raw.githubusercontent.com/alec-c4/ks-rails-bootstrap/master/template.rb

add creadentials

active_record_encryption:
  primary_key: ''
  deterministic_key: ''
  key_derivation_salt: ''
secret_key_base: ''
devise:
  secret_key: ''
google:
  client_id: ''
  client_secret: ''
postmark:
  api_key: ''

and try to login using Google

@muhammadyana
Copy link

i also got the same error, is there any update?

@BobbyMcWho
Copy link
Member

I feel like this is related to #1061, since the template you're using uses Rails 7

@omarluq
Copy link

omarluq commented Apr 14, 2022

@alec-c4 have you found a fix? im having the same issue

@fffx
Copy link

fffx commented May 25, 2022

Since omniauth set omniauth.auth by detect path in rack middleware, you can find out why omniauth.auth is empty by this :

bundle open omniauth

# edit  lib/omniauth/strategy

289     def on_callback_path?
290       puts "oncall path?: #{on_path?(callback_path)} #{callback_path}, ----- current_path: #{current_path}" # if current_path =~ / filter path/
291       on_path?(callback_path)
292     end

@seadfeng
Copy link

Since omniauth set omniauth.auth by detect path in rack middleware, you can find out why omniauth.auth is empty by this :

bundle open omniauth

# edit  lib/omniauth/strategy

289     def on_callback_path?
290       puts "oncall path?: #{on_path?(callback_path)} #{callback_path}, ----- current_path: #{current_path}" # if current_path =~ / filter path/
291       on_path?(callback_path)
292     end
devise_for :user, controllers: {   omniauth_callbacks: 'user/omniauth_callbacks' }
devise_scope :user do
    get '/auth/google_oauth2/callback' => 'user/omniauth_callbacks#google_oauth2', :as => :google_oauth2_callbacks
end

When I Changed Route ,I Got this issue
/user/auth/google_oauth2/callback => /auth/google_oauth2/callback

@ytkg
Copy link

ytkg commented Feb 6, 2023

@seadfeng I am the same way. Have you found a solution yet?

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

7 participants