Stripe Connect - retrieving access token Stripe Connect - retrieving access token curl curl

Stripe Connect - retrieving access token


Try this recipe:

install the HTTParty gem in your rails application

response = HTTParty.post("https://connect.stripe.com/oauth/token", :query => { client_secret: "#{ENV['STRIPE_SECRET_KEY']}", code: response_code, grant_type: "authorization_code" })

Then you should be able to access response['access_token'] without having to use backticks around the curl code. It worked for me.


I got it too work, probably not the prettiest way:

The first thing I learned is that curl can work inside rails if you put backticks around the curl code. This will return JSON which just needs to be formatted. I ended up with the following in my model:

customer = ActiveSupport::JSON.decode(`curl -X POST https://connect.stripe.com/oauth/token -d client_secret=#{ENV['STRIPE_SECRET_KEY']} -d code=#{self.stripe_code} -d grant_type=authorization_code`)

I then am able to extract the data from the customer hash such as "access_token":

customer['access_token']


If you are using the omniauth stripe connect strategy then it gets taken care of for you and is placed in the request.env["omniauth.auth"] in your omniauth callbacks controller.

No need to do any HTTParty, the omniauth stripe connect strategy takes care of all the things. Beauty!