You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
env['omniauth.auth'] is nil when customizing callback_path #767
I have a Rails app that "lives" in a subdirectory. To make sure the user gets to my app after authentication, I've added the following to my config/initializers/omniauth.rb:
I'm having the same exact problem with a Sinatra implementation of omniauth-twitter. If i set :callback_path, it returns to the correct place I specified in :callback_path, but request.env['omniauth.env'] is nil. And FYI, request.env['omniauth.origin'] is also nil, but you can access the value via rack session.
I'm also having the same problem. In my Rails 4.2 app, I've added following to my config/initializers/omniauth.rb: provider :foo, name: :bar, callback_path: "/sub/auth/bar/callback"
and in my callback controller, env['omniauth.auth'] is always nil
I'm not sure if this is your issue, but I had an issue with the callback path not being recognised if it contained extraneous slashes (like //auth/ldap/callback).
You may want to try removing the first slash and see if it works.
+1, have almost the same issue with rails 4.2.3 and omniauth 1.2.2. I see double slashes after callback (//auth/:provider/callback) and no Callback Phase Initiated in logs. After removing one slash it works fine. But I don't customize callback_path param
I'm having the same issue. Weirdly, it's not that request.env['omniauth.auth']is nil, rather, it returns nil, which makes it even weirder. I inspected it in better_errors, and when I type just request.env, it clearly shows the 'omniauth.auth' key and it's value, but for some reason, request.env['omniauth.auth'] returns nil nevertheless.
As soon as I remove the customized callback path, this behavior goes away, as OP suggested.
the following situation arises:
-> "request.path_info" is set to "/internal/callback" by rack
-> "on_callback_path" compares "my/custom/callback" with "/internal/callback" and returns false
--> the method callback_call is never executed.
--> env['omniauth'] is nil
I have resolved my problem through a workaround. I have posted my solution in a gist. Hoping that it will be beneficial to people like me looking out for a solution to this problem.
Provider Gem: 'omniauth', '~> 1.2.1'
Ruby Version: ruby 2.2.1p85
Platform: Ubuntu 14.04 LTS
I want to create different login flow for admin, so I have create another sessions controller under admin. But when I try to access env["omniauth.auth"] from admin/sessions_controller.rb it shows error "NoMethodError at /admin/auth/identity/callback
undefined method `[]' for nil:NilClass" I found env["omniauth.auth"] return nil
Please help me
I had the same issue as outlined by tobias74 above - my app is behind a reverse proxy with a RAILS_RELATIVE_URL_ROOT (also #903). My workaround is to add the relative URL component to full_host and set the callback_path to match the original (so "my/custom/callback" matches "/internal/callback" per tobias74) and use a querystring param (see above) if you then need to switch from the callback
OmniAuth.config.full_host = lambda do |_|
'https://www.example.com/my_relative_path'
end
config.omniauth :azure_oauth2,
client_id: ENV['AZURE_CLIENT_ID'],
client_secret: ENV['AZURE_CLIENT_SECRET'],
tenant_id: ENV['AZURE_TENANT_ID'],
callback_path: '/users/auth/azure_oauth2/callback'
For me, simply setting both client_options.redirect_uriandcallback_path did the trick. Note the former is relative, while the latter is a full URL (i.e. do not set to the same value). I guess client_options.redirect_uri is to tell the provider, and callback_path is where to expect the callback (from the standpoint of Omniauth).
Not sure you're affected by this issue? If you don't see Callback phase initiated in your console after receiving the callback, Omniauth did not recognize the (customized) callback URL (i.e. it does not care that this particular request just came in).
Reacted by Younes Serraj, Khangal and David Newberry
Thanks for opening this issue. In OmniAuth 1.x the callback path was compared against PATH_INFO, which leaves out the app's mount point, so a callback_path that included the sub-directory never matched. #903, released in v2.0.0, compares against the full request path (including SCRIPT_NAME) and prefixes the default request and callback paths with SCRIPT_NAME automatically. If you still see env['omniauth.auth'] as nil with a custom callback_path on the latest version, please open a new issue with your configuration.
Activity
geori commentedon Sep 30, 2014
I'm having the same exact problem with a Sinatra implementation of omniauth-twitter. If i set :callback_path, it returns to the correct place I specified in :callback_path, but request.env['omniauth.env'] is nil. And FYI, request.env['omniauth.origin'] is also nil, but you can access the value via rack session.
zmajstor commentedon Nov 5, 2014
I'm also having the same problem. In my Rails 4.2 app, I've added following to my
config/initializers/omniauth.rb:provider :foo, name: :bar, callback_path: "/sub/auth/bar/callback"and in my callback controller,
env['omniauth.auth']is always nildelacruzjames commentedon Feb 11, 2015
Any update im also having same problem?
mcfiredrill commentedon May 8, 2015
I'm not sure if this is your issue, but I had an issue with the callback path not being recognised if it contained extraneous slashes (like
//auth/ldap/callback).You may want to try removing the first slash and see if it works.
mcfiredrill commentedon May 8, 2015
If you don't see the
Callback Phase Initiatedmessage in your logs, then the callback_path was probably not recognised.KELiON commentedon Jul 24, 2015
+1, have almost the same issue with rails 4.2.3 and omniauth 1.2.2. I see double slashes after callback (//auth/:provider/callback) and no
Callback Phase Initiatedin logs. After removing one slash it works fine. But I don't customizecallback_pathparamPandaWhisperer commentedon Oct 13, 2015
I'm having the same issue. Weirdly, it's not that
request.env['omniauth.auth']is nil, rather, it returns nil, which makes it even weirder. I inspected it in better_errors, and when I type justrequest.env, it clearly shows the 'omniauth.auth' key and it's value, but for some reason,request.env['omniauth.auth']returns nil nevertheless.As soon as I remove the customized callback path, this behavior goes away, as OP suggested.
tobias74 commentedon Oct 18, 2015
this happens in the following situation: (applies to 1.2.2 as well as the current master)
http://www.example.com/my/custom/callback
http://www.example.com/my-rack-app/internal/callback
the following situation arises:
-> "request.path_info" is set to "/internal/callback" by rack
-> "on_callback_path" compares "my/custom/callback" with "/internal/callback" and returns false
--> the method callback_call is never executed.
--> env['omniauth'] is nil
Set callback_path explitly
jiggneshhgohel commentedon Jul 25, 2016
I am facing this similar issue. Following are the gem versions used in my application.
ruby (2.3.0)
rails (4.2.6)
omniauth-facebook (3.0.0)
omniauth-oauth2 (1.4.0)
omniauth (1.3.1)
Did anyone found a solution or a work-around for this?
jiggneshhgohel commentedon Jul 28, 2016
I have resolved my problem through a workaround. I have posted my solution in a gist. Hoping that it will be beneficial to people like me looking out for a solution to this problem.
External Links:
http://stackoverflow.com/q/38627949/936494
simonneutert commentedon May 15, 2017
i was able to retrieve the necessary data by changing
env["omniauth.auth"]torequest.env["omniauth.auth"]Rails 5.1
Devise 4.3.0
omniauth (1.6.1)
omniauth-facebook (4.0.0)
omniauth-oauth2 (1.4.0)
SandipBhowmick commentedon Nov 22, 2017
Provider Gem: 'omniauth', '~> 1.2.1'
Ruby Version: ruby 2.2.1p85
Platform: Ubuntu 14.04 LTS
I want to create different login flow for admin, so I have create another sessions controller under admin. But when I try to access env["omniauth.auth"] from admin/sessions_controller.rb it shows error "NoMethodError at /admin/auth/identity/callback
undefined method `[]' for nil:NilClass" I found env["omniauth.auth"] return nil
Please help me
nantestdeveloper commentedon Dec 1, 2017
provider: identity
calling api/v1/auth/identity/callback for api return nil auth_hash and also set the routes for same
getting error
NoMethodError at /api/v1/auth/identity/callback
===============================================
I want to call the post call api for sign in and sign up using omniauth identity
wangthony commentedon May 18, 2020
This issue has sprawled out to a bunch of different cases, but it does seem like the
callback_pathoption gets lost somehow.For an alternative solution using querystring params, see #661 (comment)
s1monj commentedon Jul 8, 2020
I had the same issue as outlined by tobias74 above - my app is behind a reverse proxy with a
RAILS_RELATIVE_URL_ROOT(also #903). My workaround is to add the relative URL component tofull_hostand set thecallback_pathto match the original (so "my/custom/callback" matches "/internal/callback" per tobias74) and use a querystring param (see above) if you then need to switch from the callbackrack 2.2.3
rails 5.2.0
omniauth 1.9.1
trkoch commentedon Feb 18, 2021
For me, simply setting both
client_options.redirect_uriandcallback_pathdid the trick. Note the former is relative, while the latter is a full URL (i.e. do not set to the same value). I guessclient_options.redirect_uriis to tell the provider, andcallback_pathis where to expect the callback (from the standpoint of Omniauth).Not sure you're affected by this issue? If you don't see
Callback phase initiatedin your console after receiving the callback, Omniauth did not recognize the (customized) callback URL (i.e. it does not care that this particular request just came in).Ignore query params when we check current_path
Ignore query params when we check current_path
Add proxy_to param to callback_path
Add proxy_to param to callback_path
Add proxy_to param to callback_path
Add proxy_to param to callback_path
khangal commentedon Jan 10, 2025
@trkoch thank you for giving me clue, in my case my
callback_path, andredirect_urineeded to be different and explicitly set because I'm using envoy.pboling commentedon Nov 6, 2025
I've documented how to accomplish using a subdirectory in the README.md of omniauth-ldap, and it mostly applies to any omniauth setup: https://github.com/omniauth/omniauth-ldap#mounted-under-a-subdirectory-script_name
sferik commentedon Oct 17, 2026
Thanks for opening this issue. In OmniAuth 1.x the callback path was compared against
PATH_INFO, which leaves out the app's mount point, so acallback_paththat included the sub-directory never matched. #903, released in v2.0.0, compares against the full request path (includingSCRIPT_NAME) and prefixes the default request and callback paths withSCRIPT_NAMEautomatically. If you still seeenv['omniauth.auth']as nil with a customcallback_pathon the latest version, please open a new issue with your configuration.