2

I am authenticating using OmniAuth with both Twitter and Instagram. Twitter is working well.

When I start the authentication process with the /auth/instagram request, OmniAuth is not including the client_id in the authorization header.

I have initialized OmniAuth as:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :twitter, ENV.fetch('TWITTER_CONSUMER_KEY'), ENV.fetch('TWITTER_CONSUMER_SECRET')
  provider :instagram, ENV.fetch('INSTAGRAM_CLIENT_ID'), ENV.fetch('INSTAGRAM_CLIENT_SECRET')
end

When I send the /auth/instagram request, it returns:

{"code": 400, "error_type": "OAuthException", 
 "error_message": "You must include a valid client_id, response_type, and redirect_uri parameters"}

and shows the request uri without my client_id:

https://www.instagram.com/oauth/authorize?client_id=&redirect_uri=http://demo.herokuapp.com/auth/instagram/callback&response_type=code&scope=basic&state=952ced9482ccf34faf3e09cffd40f59548f3c5a539499723

Any help would be appreciated.

1 Answers1

0

Your ENV variables are probably not being loaded in time / after your initializer is loaded. Try replacing them with the actual strings and see if that works. Don't commit that to a public repo... trust me it's annoying to remove if you do.

I am a fan of dotenv. I use the rails-now version to load ENV vars in initializers.

gem 'dotenv-rails', :require => 'dotenv/rails-now' in Gemfile

reference like: ENV['INSTAGRAM_ID']

cpk
  • 809
  • 1
  • 6
  • 20