Skip to content

nil error in callback_path after omniauth 2 update #1080

Closed

Description

@thisismydesign

Take a very simple strategy, such as the example from the readme. Then the following spec fails for me

  # https://github.com/omniauth/omniauth-oauth2/blob/3a43234ab5dd36a75f9c125c58fcfe1a37b26805/spec/omniauth/strategies/oauth2_spec.rb#L4-L8
  def app
    lambda do |_env|
      [200, {}, ["Hello."]]
    end
  end

  subject { described_class.new(app) }

  describe '#callback_path' do
    it 'has the correct callback path' do
      expect(subject.callback_path).to eq('/users/auth/custom/callback')
    end
  end
  1) OmniAuth::Strategies::Custom#callback_path has the correct callback path
     Failure/Error: expect(subject.callback_path).to eq('/users/auth/custom/callback')
     
     NoMethodError:
       undefined method `[]' for nil:NilClass
     
             @env['SCRIPT_NAME'] || ''
                 ^^^^^^^^^^^^^^^
     # /usr/local/bundle/gems/omniauth-2.1.0/lib/omniauth/strategy.rb:501:in `script_name'
     # /usr/local/bundle/gems/omniauth-2.1.0/lib/omniauth/strategy.rb:450:in `callback_path'

Activity

  1. BobbyMcWho commented on Jul 13, 2022

    @BobbyMcWho
    Member

    Do you have Omniauth.config.test_mode set?

  2. thisismydesign commented on Jul 13, 2022

    @thisismydesign
    Author

    @BobbyMcWho yes, I got this error with both true and false

  3. BobbyMcWho commented on Jul 13, 2022

    @BobbyMcWho
    Member

    The issue is that @env is nil, and actually lives in the Omniauth gem and not this one: https://github.com/omniauth/omniauth/blob/master/lib/omniauth/strategy.rb#L500-L502

    We could return '' if @env is nil there, if you want to spin up a PR, I can take a look, else I'll get to it when I can find some time.

  4. thisismydesign commented on Jul 13, 2022

    @thisismydesign
    Author

    @BobbyMcWho Thanks. This works in production though, so I'm wondering if there's a way to set env in the test as a workaround. But yeah env can be nil so it should be treated accordingly. I can provide a PR tomorrow

  5. shreyakurian02 commented on Oct 4, 2022

    @shreyakurian02
    Contributor

    @BobbyMcWho I have opened a PR for the same. Please do check.

  6. jeremygottfried commented on Jan 20, 2023

    @jeremygottfried

    Is there any workaround while we wait for the PR to be merged? I have the same issue with updating to 2.1.

  7. BobbyMcWho commented on Jan 20, 2023

    @BobbyMcWho
    Member

    Hmm, actually I don't believe callback path is supposed to be called without an @env having been created

  8. BobbyMcWho commented on Jan 20, 2023

    @BobbyMcWho
    Member

    I've released a fix for this in 2.1.1 which has been pushed to rubygems

  9. added theissue type 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

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions