icoretech / omniauth-spotify

OmniAuth strategy for Spotify Web API
MIT License
65 stars 25 forks source link

Always redirects to /auth/failure with message invalid_credentials #8

Open alecguintu opened 8 years ago

alecguintu commented 8 years ago

Hello guys. I need to use omniauth-spotify but there seems to be an error I always get. It always redirects me to /auth/failure directly even before I get to do any puts on my callback action.

127.0.0.1 - - [18/Dec/2015 16:23:58] "GET /auth/spotify HTTP/1.1" 302 309 0.0523
127.0.0.1 - - [18/Dec/2015 16:24:00] "GET /auth/spotify/callback?code=AQDayxIRszbIYj_YQwCkYD3AYo2oDzKJVv9pl7zft54UjvaXccJCBGfc2e27J8aRDggirFK6H2mxXanE_OBTv9XVqoVGhw-5oFIJvD00448qVyzaNHAXanAnsx7_bPm5rbrrSFS12uNYVKpUT52hVH8OiEdXYxCjGqhAHDscCnoo5FY4u4ttTZHGDAGg9Y1tS6R0cdh5-Pc_HrPMzCGWR3qY_7WumIyJJJIsyvIMXzTeSP3rvt4j__BMZpN0rA6a-TwNAnGuW3fvIOQvO7PEagx4qvLK83issPev-LSG-A&state=da7dbbee0e89eb9a1abd9e6979b110936981eab12e5866a3 HTTP/1.1" 302 9 0.8371
127.0.0.1 - - [18/Dec/2015 16:24:00] "GET /auth/failure?message=invalid_credentials&origin=http%3A%2F%2Flocalhost%3A3000%2F42&strategy=spotify HTTP/1.1" 301 88 0.0491
127.0.0.1 - - [18/Dec/2015 16:24:00] "GET / HTTP/1.1" 302 - 0.0570

I have on my Spotify App is callback: http://localhost:3000/auth/spotify/callback

I can provide more info if I need to.

masterkain commented 8 years ago

can you show how are you initializing the gem? make sure to obscure used credentials.

alecguintu commented 8 years ago

omniauth.rb

OmniAuth.config.logger = Rails.logger

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :twitter, ENV['TWITTER_CONSUMER_KEY'], ENV['TWITTER_CONSUMER_SECRET']
  provider :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_APP_SECRET'], scope: 'public_profile', display: 'popup', info_fields: 'id,name,first_name,last_name,gender,about,bio,birthday,link'
  provider :spotify, ENV['SPOTIFY_CLIENT_ID'], ENV['SPOTIFY_CLIENT_SECRET'], scope: 'user-follow-modify user-read-private playlist-read-private'
end

# https://github.com/intridea/omniauth/wiki/FAQ#wiki-omniauthfailureendpoint-does-not-redirect-in-development-mode
# Open ticket on a better fix for this https://github.com/intridea/omniauth/issues/616
OmniAuth.config.on_failure = Proc.new { |env|
  OmniAuth::FailureEndpoint.new(env).redirect_to_failure
}

Gemfile (Gems I'm using just in case):

gem 'omniauth-twitter', '~> 1.0'
gem 'twitter', '~> 4.8'
gem 'omniauth-facebook', '~> 3.0'
gem 'omniauth-spotify', '~> 0.0.9'
alecguintu commented 8 years ago

Hello guys. First off, happy new year to you guys! Any leads to this? Any help would be appreciated.

ross-alcazar commented 8 years ago

I also have the same problem when i use facebook as login. I'd be happy to have a solution for this. thanks advance.

dennislysenko commented 8 years ago

+1, this is with 0.0.9. Any leads on this? The gem just flat out doesn't work for me at the moment.

masterkain commented 8 years ago

can you try some of the potental workarounds listed here? https://github.com/icoretech/omniauth-spotify/issues/7#issuecomment-155031356

hannahhoward commented 8 years ago

@masterkain it appears omniauth-oauth2 has permanently added the query string back to the callback_url in v1.4.0 and doesn't seem to be planning to remove it. other projects such as omniauth-google-oauth2 have permeantly locked on omniauth-oauth2 1.3.1 until it's fixed, or overriding the callback_url in the strategy. we resolved by manually setting a gem dependency for an early version of omniauth-oauth2. perhaps it's worth locking omniauth-spotify below 1.3.1 or overriding callback_url in the strategy?