Devise & Omniauth-soundcloud error -- invalid_request: Required parameter is missing: client_id

247 views Asked by At

Using Rails 4.2.2

Very similar issue to what's happening with this question: Missing client_id with Devise and Facebook-Omniauth

Except that this is for omniauth-soundcloud, and the above question doesn't have an actual answer. The answer chosen is to follow the railscast, which is what I've been doing to set this up in the first place. (I'm following the railscast pro #235)

My devise.rb:

config.omniauth :soundcloud, ENV["blablabla"], ENV["blablabla"]

(obviously blablabla is my client id and secret)

Gemfile:

gem 'devise'
# gem 'omniauth'
gem 'omniauth-soundcloud', '~> 1.0.0'
# gem 'omniauth-oauth2'

(commented those two out because some answers online said that commenting them out fixes the issue, but not the case for me)

my user.rb:

devise :database_authenticatable, :registerable, :omniauthable, 
     :recoverable, :rememberable, :trackable, :validatable

even in the URL I can see the client id is missing, but I have it defined in my devise.rb file as shown above

https://soundcloud.com/connect?client_id=&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fusers%2Fauth%2Fsoundcloud%2Fcallback.....

I can't figure out why the client id isn't being passed along. Did I miss something? Am I supposed to define it somewhere else as well? Having an omniauth.rb file to define it will conflict with the devise.rb initializer so that's not the solution either.

1

There are 1 answers

0
Josh Burson On BEST ANSWER

Figured it out. Just don't follow the railscast. Follow this instead:

https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview

My particular issue was that I needed to declare omniauth_providers in the user model:

devise :database_authenticatable, :registerable, :omniauthable, 
     :recoverable, :rememberable, :trackable, :validatable, omniauth_providers: [:soundcloud]

I also had to change my devise.rb away from what omniauth-soundcloud suggests:

config.omniauth :soundcloud, ENV["SOUNDCLOUD_CLIENT_ID"], ENV["SOUNDCLOUD_CLIENT_SECRET"]

to this:

config.omniauth :soundcloud, "SOUNDCLOUD_CLIENT_ID", "SOUNDCLOUD_CLIENT_SECRET", client_options: { redirect_uri: '/users/auth/soundcloud/callback' }

This should fix it for anyone having this issue.