Gautam Moradiya
Gautam Moradiya

Reputation: 11

RAILS Quickbook oauth2 convert url to Net ::HTTP request

I need to convert below post request into Rails Net::HTTP request.

POST https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer HTTP/1.1 
Accept: application/json 
Authorization: Basic UTM0dVBvRDIwanp2OUdxNXE1dmlMemppcTlwM1d2NzRUdDNReGkwZVNTTDhFRWwxb0g6VEh0WEJlR3dheEtZSlVNaFhzeGxma1lXaFg3ZlFlRzFtN2szTFRwbw==
Content-Type: application/x-www-form-urlencoded
Host:oauth.platform.intuit.com
Body: grant_type=authorization_code&code=L3114709614564VSU8JSEiPkXx1xhV8D9mv4xbv6sZJycibMUI&redirect_uri=https://www.mydemoapp.com/oauth-redirect

I'm using this documentation

https://developer.intuit.com/app/developer/qbpayments/docs/develop/authentication-and-authorization/oauth-2.0#exchange-code-for-refresh-and-access-tokens

Upvotes: 1

Views: 257

Answers (1)

Vishal
Vishal

Reputation: 828

You can use Rails Net::HTTP class itself for this purpose. Try,

require 'net/http'

url = URI.parse('https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer')
req = Net::HTTP::Post.new(url.to_s)
res = Net::HTTP.start(url.host, url.port) {|http|
  http.request(req)
}
puts res.body

For more details see

Upvotes: 1

Related Questions