Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

"uninitialized constant Net::HTTP" when RAILS_ENV=production #33

Closed
hiddenwaffle opened this issue Jul 22, 2017 · 1 comment
Closed

Comments

@hiddenwaffle
Copy link

Summary

When using this gem with Rails 5.1.2 with Ruby 2.4.1, opening path /auth/azureactivedirectory gives this error:

NameError (uninitialized constant Net::HTTP):
omniauth-azure-activedirectory (1.0.0) lib/omniauth/strategies/azure_activedirectory.rb:169:in `fetch_openid_config'

The error does not occur in development mode. It only occurs when RAILS_ENV=production. Tested on Ubuntu 16.04 and the macOS Sierra.

Steps to reproduce

  1. Create a new test project:
rails new testproject
cd testproject
  1. Add gem to Gemfile:
gem 'omniauth-azure-activedirectory'
  1. Update gems and Gemfile.lock from Gemfile:
bundle
  1. Add omniauth.rb to config/initializers:
Rails.application.config.middleware.use OmniAuth::Builder do
  provider :azure_activedirectory, ENV['AAD_CLIENT_ID'], ENV['AAD_TENANT']
  # other providers here
end
  1. Run server:
AAD_CLIENT_ID=clientId AAD_TENANT=tenantId RAILS_ENV=production bin/rails server
  1. Navigate to http://localhost:3000/auth/azureactivedirectory
  2. Error should appear in logs/production.log:
...
NameError (uninitialized constant Net::HTTP):
omniauth-azure-activedirectory (1.0.0) lib/omniauth/strategies/azure_activedirectory.rb:169:in `fetch_openid_config'
...

Workaround

I was able to successfully work around this issue by requiring the module in my application.rb file:

require 'net/http'

Root Cause

I suspect that something runs in Rails development that that requires net/http ahead of time. Nevertheless, do you think that the azure_activedirectory.rb file the omniauth-azure-activedirectory gem should require net/http on its own since it refers to the constant in the fetch_openid_config method on line 169 of that file?

@hiddenwaffle
Copy link
Author

Never mind, I see that PR #31 will fix this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant