dnsimple-ruby icon indicating copy to clipboard operation
dnsimple-ruby copied to clipboard

Handle OAuth errors properly

Open jacegu opened this issue 9 years ago • 1 comments

I've found a case that doesn't match the error message handling scenarios that we currently have. When getting the OAuth access token, if you provide an incorrect secret you will get an error. The response is a 400 JSON response, however it doesn't include a message in the returned object:

#<HTTParty::Response:0x7fadab21aab0 parsed_response={"error"=>"invalid_request", "error_description"=>"Incorrect authorization credentials"}, @response=#<Net::HTTPBadRequest 400 Bad Request readbody=true>, @headers={"server"=>["nginx"], "date"=>["Sat, 23 Apr 2016 13:59:34 GMT"], "content-type"=>["application/json; charset=utf-8"], "transfer-encoding"=>["chunked"], "connection"=>["close"], "status"=>["400 Bad Request"], "x-ratelimit-limit"=>["30"], "x-ratelimit-remaining"=>["29"], "x-ratelimit-reset"=>["1461423574"], "cache-control"=>["no-cache"], "x-request-id"=>["e4a75b48-5a97-43cf-9be7-8a4a43f68589"], "x-runtime"=>["0.065750"]}>

The response is structured this way to comply with the OAuth RFC so we should be able to handle this case in the client too.

jacegu avatar Apr 23 '16 14:04 jacegu

That's correct. In the Go client I already patched it as we spotted this issue while working on one of the addons. https://github.com/aetrion/dnsimple-go/commit/ce4241ee6b4fbbe9e3b106527c8e5a19d783e2e4

So far, all the clients have two methods: a low level request method that performs the http request and wraps the HTTP client, and an higher level method that performs the request and performs some essential validations.

To solve this issue, the approach I used is to bypass the high level method for this endpoint, and handle the error directly. I think we can follow the same approach in the Ruby client as the request method is already an abstraction over the HTTP client.

weppos avatar Apr 26 '16 14:04 weppos