1

So I'm trying to make an app where I want to allow users to login using their Instagram accounts. This is a Rails app. I'm mostly following Railscast 241 for doing this except that I use Instagram API instead of Twitter API. I'm not using devise.

I installed the gem 'omniauth-instagram' and I have the following in one of my initializers -

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :developer unless Rails.env.production?
  provider :instagram, ENV['MY_CLIENT_ID'], ENV['MY_CLIENT_SECRET']
end

The problem is that when I direct the user to the 'auth/instagram' path the request does not contain my client-id (I check the Chrome debugging tools > Network to make sure of this). And as a result, although it takes the user to the login page, but then it fails and gives the following response -

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

So instead of making the request o 'auth/instagram' path I direct the user to the actual autorization URL i.e.

https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=code

And all goes according to the plan. Except that I don't get the user information as a part of request.env['omniauth.auth'] inside my controller method (after being successfully redirected to the right URL). Infact request.env hash does not have omniauth.auth as one of its keys. The fix to this is that I'll manually have to write a curl -F query to the API to get the user information.

But that sounds like too much work and I feel there must be something that I might have been doing wrong. Why isn't the gem making the correct request with my provided client_id? and why isn't 'omniauth.auth' get properly populated as part of the params?

Some relevant resources -

Instagram API authentication page

omniauth-instagram gem

satnam
  • 1,457
  • 4
  • 23
  • 43
  • http://stackoverflow.com/questions/35618343/unable-to-authenticate-with-omniauth-instagram-client-id-missing/36873557#36873557 – cpk Apr 26 '16 at 19:01

0 Answers0