Skip to content

When calling /auth/:identity/callback.json , request.env["omniauth.auth"] is nil #618

Closed

Description

@andrei4002

Let's say that I have to connect with facebook.

My app works perfectly if i call

/auth/facebook/callback

or

/auth/facebook/callback?format=json

but when i try to call

/auth/facebook/callback.json

there is no request.env[ "omniauth.auth" ]

(it's nil)

Any ideas of what's going on? (I'll provide more additional info if asked. not sure what else is needed)

Activity

  1. jphenow commented on Jul 6, 2012

    @jphenow

    👍 Though I'm having the issue with a a custom provider - working on ownership of both the provider and the client

  2. xlozinguez commented on Aug 12, 2012

    @xlozinguez

    Thanks @andrei4002 , you solved an issue of mine... can't figure out why callback.js wouldn't work... anyway callback?format=js does the trick for us ;)

  3. BartlomiejSkwira commented on Aug 30, 2013

    @BartlomiejSkwira

    Same problem here on a rails-api app which renders just json. In my case a Google Api redirect_uri can't be with parameters, when I try to add ?format=json in console and midddleware initializer I get

    (google) Authentication failure! invalid_credentials: OAuth2::Error, redirect_uri_mismatch:                                                                                              
    {                                                                                                           
      "error" : "redirect_uri_mismatch"                                                                                                                                               
    }
    

    Seems that I will have to respond to html and set session manually.

  4. adammcnamara commented on Nov 14, 2014

    @adammcnamara

    +1 to this issue. Does anyone know the root cause why .json doesn't work?

  5. philipgiuliani commented on Aug 3, 2015

    @philipgiuliani

    Still open after 3 years? Have the same issue, and it really should get fixed..

  6. Dragsbaek commented on Dec 31, 2015

    @Dragsbaek

    +1

  7. tzafrir commented on Jan 11, 2016

    @tzafrir

    Still causing headaches in 2016

  8. tzafrir commented on Jan 11, 2016

    @tzafrir

    I browsed a little and it seems that in https://github.com/intridea/omniauth/blob/master/lib/omniauth/strategy.rb,

    callback_path is hardcoded to be /auth/facebook/callback, and when current_path is compared to expected strategy's path (current_path.casecmp(path) == 0) the test fails and omniauth doesn't kick in.

    Quick fix: use ?format=json

  9. tmilewski commented on Feb 12, 2017

    @tmilewski
    Member

    @tzafrir is correct. What are the use-cases of redirecting a callback/user to a .json file?

  10. babgyy commented on Jul 31, 2018

    @babgyy

    The use-cases are to integrate Facebook Login with a client-side workflow. Instead of 302 redirecting the client to facebook then back to /auth/facebook/callback you do :

    1. Browser async calls Facebook who returns authentication hash
    2. Browser async calls /auth/facebook/callback.json to validate the authentication hash
    3. Browser can then decide wether to proceed or not and the page was not changed during the process
  11. babgyy commented on Jul 31, 2018

    @babgyy

    Thanks @andrei4002, after all this time, your solution does the job, and should definitely be in the docs

  12. lasseebert commented on Jun 22, 2022

    @lasseebert

    I'm still looking for a workaround. In my case I want to have multiple providers point to the same callback-url, which is not possible with the workaround given here.

  13. lasseebert commented on Jun 22, 2022

    @lasseebert

    I found a solution: Use both redirect_uri and callback_path, which should match:

    Rails.application.config.middleware.use OmniAuth::Builder do
      provider :google_oauth2, client_id, client_secret,
               name: :my_custom_name,
               redirect_uri: "https://myapp.com/non-default/path",
               callback_path: '/non-default/path'
    end

    You still initalize the oauth by POST /auth/my_custom_name, but the callback happens the given redirect_uri and with the callback_path set, request.env['omniauth.auth'] is set correctly.

  14. added theissue type on Oct 17, 2026
  15. marked Callback problem #802 as a duplicate of this issue on Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions