socialcast / devise_oauth2_providable

Rails3 engine integrating OAuth2 authentication with Devise
MIT License
219 stars 102 forks source link

env variables not set? #13

Closed tute closed 12 years ago

tute commented 13 years ago

I'm trying to use it but I've run into some issues. Out of the box, when I grant access to a client app, oauth2/token does not see the current user (but there is one):

Started POST "/oauth2/token" for 127.0.0.1 at 2011-08-17 16:02:30 -0300
  Processing by Oauth2::TokensController#create as 
  Parameters: {"grant_type"=>"authorization_code", "code"=>"09e3b07c2a2ebb692a961c01afecebd3", "client_id"=>"120094574673767", "client_secret"=>"[FILTERED]", "redirect_uri"=>"http://localhost:9393/oauth/callback"}
Completed   in 16ms

Started POST "/users/sign_in" for 127.0.0.1 at 2011-08-17 16:02:31 -0300
  Processing by Devise::SessionsController#create as 
  Parameters: {"grant_type"=>"authorization_code", "code"=>"09e3b07c2a2ebb692a961c01afecebd3", "client_id"=>"120094574673767", "client_secret"=>"[FILTERED]", "redirect_uri"=>"http://localhost:9393/oauth/callback"}
Completed   in 61ms
  Processing by Devise::SessionsController#new as 
  Parameters: {"grant_type"=>"authorization_code", "code"=>"09e3b07c2a2ebb692a961c01afecebd3", "client_id"=>"120094574673767", "client_secret"=>"[FILTERED]", "redirect_uri"=>"http://localhost:9393/oauth/callback"}
Rendered /Users/tute/.rvm/gems/ruby-1.9.2-p290/gems/devise-1.4.2/app/views/devise/shared/_links.erb (2.2ms)
Rendered /Users/tute/.rvm/gems/ruby-1.9.2-p290/gems/devise-1.4.2/app/views/devise/sessions/new.html.erb within layouts/application (13.4ms)
Completed 200 OK in 37ms (Views: 24.6ms | ActiveRecord: 0.0ms)

If I comment the before filters from the gem controllers, I get:

Started POST "/oauth2/token" for 127.0.0.1 at 2011-08-17 16:04:53 -0300
  Processing by Oauth2::TokensController#create as 
  Parameters: {"grant_type"=>"authorization_code", "code"=>"5a76d626ab5a1d2e7e334e8c95a90d0f", "client_id"=>"120094574673767", "client_secret"=>"[FILTERED]", "redirect_uri"=>"http://localhost:9393/oauth/callback"}
Completed 500 Internal Server Error in 1ms

NoMethodError (undefined method `refresh_tokens' for nil:NilClass):

The nil object comes from Oauth2::TokensController#oauth2_current_client, which returns env['oauth2.client'].

Why is this happening? Thanks in advance,

TuteC.

tute commented 13 years ago

It seems I can't run the related test. For running the integration specs on the rails_app inside the gem, do I need to do 'rake spec'?

It always executes 70 succesful examples, regardless of my changes to 'Oauth2AuthorizationCodeGrantTypeStrategy'.

colszowka commented 13 years ago

Seeing the same :(

colszowka commented 13 years ago

Try adding :oauth2_authorization_code_grantable in your User model, you need all 4 of them (see spec/rails_app/app/models/user.rb - it's missing from the setup instructions in the README. I submitted a pull request. For me this made things work.