icoretech / omniauth-spotify

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

Issue with callback_url #6

Closed snags88 closed 9 years ago

snags88 commented 9 years ago

There seems to be an issue with the callback_url in the authentication process. I set up the callback URI on the Spotify Application to be http://localhost:3000/auth/spotify/callback and i've set up my routes to be get '/auth/:provider/callback', to: 'sessions#create'

When I go through the authentication process, it give me the following error:

OAuth2::Error at /auth/spotify/callback
invalid_grant: Invalid redirect URI
{"error":"invalid_grant","error_description":"Invalid redirect URI"}

Here is a snippet from the server log:

Started GET "/auth/spotify/callback?code=AQCypnu2Hre0Ky6kbdSQ69pLY-4t9hQ_ASMvZTm5U-1zdwvEYpm-C3oSRnU1EiDFfop5XqGfBTWYSbY_he7MO0jwy6-OE1skynHwSTCL0Aq1o2waJ52coPXdgHRIeuunA-E1HeJOcmLFA1bP11I773wKSysk5CMONcerHEhXoAwa1fdMjqp8lDRG3UCCB0yrYrYsIixMeftTGrZDD4yMjJ7b4gqAMK4ESCb86ePtT0Pz_BbweJ0TSYleZ69b5FBGZU2QbnobAQqCyO8&state=272475e91eba320627f3802ed39dc76331aae22243942bf9" for 127.0.0.1 at 2015-04-19 20:35:45 -0400
I, [2015-04-19T20:35:45.897996 #24960]  INFO -- omniauth: (spotify) Callback phase initiated.
E, [2015-04-19T20:35:46.562234 #24960] ERROR -- omniauth: (spotify) Authentication failure! invalid_credentials: OAuth2::Error, invalid_grant: Invalid redirect URI
{"error":"invalid_grant","error_description":"Invalid redirect URI"}

OAuth2::Error - invalid_grant: Invalid redirect URI
{"error":"invalid_grant","error_description":"Invalid redirect URI"}:
  oauth2 (1.0.0) lib/oauth2/client.rb:113:in `request'
  oauth2 (1.0.0) lib/oauth2/client.rb:138:in `get_token'
  oauth2 (1.0.0) lib/oauth2/strategy/auth_code.rb:29:in `get_token'
  omniauth-oauth2 (1.2.0) lib/omniauth/strategies/oauth2.rb:93:in `build_access_token'
  omniauth-oauth2 (1.2.0) lib/omniauth/strategies/oauth2.rb:75:in `callback_phase'
  omniauth (1.2.2) lib/omniauth/strategy.rb:227:in `callback_call'
  omniauth (1.2.2) lib/omniauth/strategy.rb:184:in `call!'
  omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
  omniauth (1.2.2) lib/omniauth/builder.rb:59:in `call'

When I switched over to the rspotify gem, I got through to my sessions#create action. Any idea what's going on?

wulffeld commented 9 years ago

This might be because of this:

https://github.com/icoretech/omniauth-spotify/blob/master/lib/omniauth-spotify.rb#L54-L57

You can try and use this fork https://github.com/jrichardlai/omniauth-spotify or monkeypatch it by:

module OmniAuth
  module Strategies
    class Spotify < OmniAuth::Strategies::OAuth2
      remove_method :callback_url
    end
  end
end
masterkain commented 9 years ago

I released 0.0.8 reverting the change introduced in https://github.com/icoretech/omniauth-spotify/pull/5

Thanks for the suggestions and let me know if this issue can be closed.

wulffeld commented 9 years ago

@masterkain You mean 0.0.6, right? That's the latest version.

The presence of the callback_url method breaks the auth process for me.

masterkain commented 9 years ago

sorry, it's 0.0.8 but I just pushed to rubygems.

cheers

wulffeld commented 9 years ago

@masterkain :+1: works for me.

snags88 commented 9 years ago

@masterkain works for me. Thanks for the quick turn around!