doorkeeper-gem / doorkeeper

Doorkeeper is an OAuth 2 provider for Ruby on Rails / Grape.
https://doorkeeper.gitbook.io/guides/
MIT License
5.32k stars 1.07k forks source link

undefined method `body' for #<Doorkeeper::OAuth::CodeResponse:0x00000007ea2520> #259

Closed barmstrong closed 10 years ago

barmstrong commented 11 years ago

Sometimes we get errors like these in authorizations_controller.rb on create and destroy: https://github.com/applicake/doorkeeper/blob/master/app/controllers/doorkeeper/authorizations_controller.rb#L26

A NoMethodError occurred in authorizations#create:
undefined method `body' for #<Doorkeeper::OAuth::CodeResponse:0x00000007ea2520>
app/controllers/oauth/authorizations_controller.rb:33:in `create'

The redirect URI being passed in is for mobile clients and looks something like: ura:jeaf:xg:oauth:2.0:oob.

So it can't call redirect_to auth.redirect_uri. What is the correct server response for one of these? I'm thinking something like this?

def create
  auth = authorization.authorize
  if auth.redirectable?
    if auth.redirect_uri =~ URI::regexp
      redirect_to auth.redirect_uri
    else
      render nothing: true
    end
  else
    render :json => auth.body, :status => auth.status
  end
end

Also, what do you call these 'mobile client' redirects? Not even sure the correct name to google for. Thanks!

tute commented 10 years ago

Thanks for your input. Is this fixed through https://github.com/doorkeeper-gem/doorkeeper/blob/84f809aa98fcde3272d45e0381ebb6829df8f8f7/lib/doorkeeper/oauth/error_response.rb#L32-L35?

tute commented 10 years ago

Or should we put that logic in https://github.com/doorkeeper-gem/doorkeeper/blob/685a5f3ed52c87c8bc951297dbe2d664b3d63ec8/lib/doorkeeper/oauth/code_response.rb#L14-L16 as well?

tute commented 10 years ago

It's now fixed through: https://github.com/doorkeeper-gem/doorkeeper/blob/685a5f3ed52c87c8bc951297dbe2d664b3d63ec8/lib/doorkeeper/oauth/code_response.rb#L20-L21. Thanks for your input!