Skip to content

Facebook authentication not working with custom callback path #661

Closed as not planned

Description

@javidjamae

I'm not sure if this is related to issue #630 or not. I posted this as a question on Stack Overflow, but I'll post it again here as I feel like it may be a bug:

I'm using devise / omniauth to authenticate my Rails app against Facebook. I'm trying to change the callback_path to be something custom, but no matter what I set it to, the omniauth.auth request variable comes back as nil. For example, here I'm setting the callback_path to the exact value that it is if I don't set it:

Devise.setup do |config |    
  require "omniauth-facebook"
  config.omniauth :facebook, 
    ENV['FACEBOOK_APP_ID'], 
    ENV['FACEBOOK_APP_SECRET'], 
    scope: "email",
    :setup => lambda { |env| 
       env['omniauth.strategy'].options[:callback_path] = "user/auth/facebook/callback"
    }
end

If I don't set the :callback_path, then authentication works and I get data back in the omniauth.auth request variable. But, I have to override it because I need to support passing an attribute back on the callback.

I've looked through the Omniauth::Strategy code to see what might be going wrong, but I can't quite figure out what's going wrong.

My questions:
Is this a bug?
Why is this not working?
Is there a better way to solve the problem?

Activity

  1. brauliobo commented on Dec 19, 2013

    @brauliobo

    had to force this too with persona and twitter. The use callback_path in the provider method call with setup doesn't seems to work

  2. delacruzjames commented on Feb 11, 2015

    @delacruzjames

    any work around for this?

  3. wangthony commented on May 18, 2020

    @wangthony

    Definitely seems like a bug. The callback_path that is set by setup proc gets lost somehow. I tried tracking it down, but ran out of time. It's in the Omniauth::Strategy::Options during the request phase, but doesn't appear in the callback request.

    In any case, a workaround is to use a querystring param on your provider URL, e.g. /auth/<provider>?my_auth_type=some_value'. The param will get passed back to you with the callback request. In your controller's callback action, you can then examine the value of params[:my_auth_type]` and write your logic based on that.

    I've verified that this works for Auth0 but haven't tried it on others.

  4. added theissue type on Oct 17, 2026
  5. sferik commented on Oct 20, 2026

    @sferik
    Contributor

    OmniAuth decides whether a request is the callback before the setup phase runs, so a callback_path set in setup affects the URL sent to the provider, but the callback request then never matches it. (The example's path is also missing its leading slash.) Pass callback_path as a provider option instead, as a string or as a lambda that returns true for the callback request. Closing since this is how it's designed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions