Debugging Net::HTTP and Ruby OAuth

Posted on 23 Feb 2011

There’s a handy method on Net::HTTP which allows you to send detailed debugging information (including request and response headers/bodies) to a stream. The OAuth gem uses Net::HTTP and it’s easy to get at. For example, you can write debug info to your web server’s log like this:

# Create a consumer
consumer = OAuth::Consumer.new("key", "secret", :site => "https://agree2")

# Enable debugging
consumer.http.set_debug_output($stderr)

# Do stuff
request_token = consumer.get_request_token(:oauth_callback => "http://example.com")