I'm using a Rails app with Devise (for authentication) and the omniauth gem on a remote server. When I used to deploy to Heroku, I could set environment variables in the terminal, but that's not offered on the remote server I'm using. I therefore added the following to the bottom of .bashrc
export TWITTER_KEY="LxAuQ1Chmas;dlfkjdsal;fjds" TWITTER_SECRET="CC2XpLOeMJbvYphlafsdlkfjdsalkfj"
hoping that would set the environment variables configured in the Devise.rb file
config.omniauth :twitter, ENV["TWITTER_KEY"], ENV["TWITTER_SECRET"]
However, when I try to sign in with Twitter, I'm getting this
OAuth::Unauthorized (401 Unauthorized):
oauth (0.4.7) lib/oauth/consumer.rb:216:in `token_request'
oauth (0.4.7) lib/oauth/consumer.rb:136:in `get_request_token'
omniauth-oauth (1.0.1) lib/omniauth/strategies/oauth.rb:29:in `request_phase'
omniauth-twitter (1.0.0) lib/omniauth/strategies/twitter.rb:63:in `request_phase'
omniauth (1.1.4) lib/omniauth/strategy.rb:214:in `request_call'
so I'm assuming the environment variables aren't be read correctly. Can you explain another way I might set them?
I would suggest managing environment variables with the figaro gem.
Put environment variables in the yaml configuration file and they will be available in ENV.
It also provides a helpful rake task to set the variables on Heroku.
Related
My pplication is running on Ruby 2.7 / Rails 5.2.4 on Windows 10 and SUSE (SLES 15.SP3).
It uses Devise for authentication, with omniauth-keycloak, which worked fine for several months.
This morning I had tu run "bundle update" for an unrelated subject. After this update, invoking the link to Keycloak remote server for authentication issues the following error:
DEBUG -- omniauth: (keycloakopenid) Going to get Keycloak configuration. URL: https://identity-a.manage.ch/realms/bfs-sis-a/.well-known/openid-configuration
E, [2022-07-19T08:57:43.384693 #13364] ERROR -- omniauth: (keycloakopenid) Authentication failure! uninitialized constant OmniAuth::Strategies::KeycloakOpenId::MultiJson: NameError, uninitialized constant OmniAuth::Strategies::KeycloakOpenId::MultiJson
Processing by Users::OmniauthCallbacksController#failure as HTML
And redirects to the sign-in page.
The OmniAuth::Strategies::KeycloakOpenId::MultiJson constant does not exist in the project indeed.
The closest constant OmniAuth::Strategies::KeycloakOpenId is used in the devise.rb initializer:
config.omniauth :keycloak_openid,
"BFS.SIS",
client_options: { base_url: '', site: Rails.application.credentials.integration[:authentication_url], realm: "bfs-sis-a" },
strategy_class: OmniAuth::Strategies::KeycloakOpenId
Installed gem versions are:
devise (4.8.1)
oauth2 (2.0.6)
omniauth (2.1.0)
omniauth-oauth2 (1.7.3)
omniauth-keycloak (1.4.2)
omniauth-rails_csrf_protection (1.0.1)
How could I solve this issue?
When I try to log in with omniauth(facebook) I get Invalid credentials error in production but it works fine in local.
I already added the urls in Valid OAuth redirect URIs
The callbacks I get are
/auth/facebook/callback?code=....
CallbacksController#failure
The gems I have.
oauth2 (1.2.0)
omniauth (1.3.1)
omniauth-facebook (4.0.0)
omniauth-oauth2 (1.4.0)
The solution was removing my IP from Server IP Whitelist
OAuth Error: This IP can't make requests for that application
I'm having trouble in production on Heroku, with Devise confirmable email. I'd been using Mailgun for this and am migrating to Mandrill. All references to Mailgun have been removed from the code, so a search for "mailgun" comes up empty, including my vendor folder. My new setup is for Mandrill SMTP. When I test signing up a user on Heroku my output includes this:
Net::SMTPAuthenticationError (535 5.7.0 Mailgun is not loving your login or password
vendor/ruby-2.1.2/lib/ruby/2.1.0/net/smtp.rb:969:in `check_auth_response'
vendor/ruby-2.1.2/lib/ruby/2.1.0/net/smtp.rb:740:in `auth_plain'
vendor/ruby-2.1.2/lib/ruby/2.1.0/net/smtp.rb:732:in `authenticate'
vendor/ruby-2.1.2/lib/ruby/2.1.0/net/smtp.rb:567:in `do_start'
vendor/ruby-2.1.2/lib/ruby/2.1.0/net/smtp.rb:520:in `start'
vendor/bundle/ruby/2.1.0/gems/mail-2.6.3/lib/mail/network/delivery_methods/smtp.rb:112:in `deliver!'
I've removed my Heroku ENV variables, removed the Mailgun addon but it seems like there's a setting which is not part of my code that needs to be updated to resolve this. Why is it stuck on Mailgun?
I am an idiot. I had an ENV variable for SMTP_ADDRESS which I was using for both applications. It was still set to Mailgun's url.
I have a rails app which provides real-time functionality through Faye. My clients are going to access the Faye server through example.com:9292/faye. Instead of using that address and revealing my machine's open ports, I am trying to add a rack middleware and by using 'rack-proxy' gem, proxy my example.com/faye requests to example.com:9292/faye. My Rails middleware code looks like this:
class FayeProxy < Rack::Proxy
def rewrite_env(env)
request = Rack::Request.new(env)
if request.path =~ %r{^/faye}
env["HTTP_HOST"] = "localhost:9292"
end
env
end
end
Also I added the middleware to config/application.rb by config.middleware.use "FayeProxy", but when I run my rails server I get the following error:
/gems/ruby-1.9.3-p194/gems/rack-proxy-0.5.0/lib/rack/proxy.rb:12:in 'initialize': undefined method `key?' for # (NoMethodError)
and even if I remove meta_request gem I will get
*/gems/ruby-1.9.3-p194/gems/rack-proxy-0.5.1/lib/rack/proxy.rb:12:in initialize': undefined methodkey?' for # (NoMethodError)
*
Any help is really appreciated if anybody has experienced this before or knows the solution.
P.s. I'm using Rails 3.2.13, rack 1.4.5, rack-proxy 0.5.1.
It seems that the rack proxy shall not be treated as middleware, rather it should be mounted via routes as described here: http://inductor.induktiv.at/blog/2010/05/23/mount-rack-apps-in-rails-3/.
I know this is old, but I was just having a similar issue, but I suspect that the folder you faye_proxy.rb is in is not included in rails by default.
Adding an initializer maybe ./config/initializers/proxy.rb which contains
require "#{Rails.root}/lib/faye_proxy.rb"
Replace lib with wherever you put the proxy.
I use Rails 2.3.5 and want to use Omniauth however I can't get them to work together, as rails 2.3.5 requies Rack 1.0.1 and Omniauth (version 0.1.6) requires Rack 1.1
I deploy on Heroku so I don't believe I can hack into Rails and remove the hard dependency on version 1.0.1 of Rack.
Any help very much appreciated.
Paul
We had a similar issue. We were on Rails 2.3.4 and wanted to use OmniAuth (0.2.6). Unfortunately the only possible solution I've found so far is to upgrade to Rails 2.3.8 or later which runs on Rack 1.1 (the minimum required by OmniAuth) and then require OmniAuth like so:
# In config/environment.rb require 'omniauth' (or 'oa-<strategy_name>') before Rails::Initialize
require 'omniauth'
Rails::Initializer.run do |config|
...
# Add your own initializer for OmniAuth
# /config/initializers/omniauth.rb
ActionController::Dispatcher.middleware.use OmniAuth::Builder do
# your strategy provider logic
end
This was mostly groomed from this thread / links in it: http://groups.google.com/group/omniauth/browse_thread/thread/676fa835428e9c83
Unfortunately I'm in the middle of all of this right now so I can't promise this works fully as I'm using a custom strategy and haven't quite made it all the way to the end yet. Hopefully it provides some starting points for you to dig deeper if you're still stuck on this if nothing else.