OAuth2.0 for Pinterest Fails

Hi everyone! Thanks for the help in advance.

curl -X POST https://api.pinterest.com/v5/oauth/token
--header 'Authorization: Basic {base64 encoded string made of client_id:client_secret}'
--header 'Content-Type: application/x-www-form-urlencoded'
--data-urlencode 'grant_type=refresh_token'
--data-urlencode 'refresh_token={YOUR_REFRESH_TOKEN}'
--data-urlencode 'scope=boards:read'
  • Question:
    What would be the right way to set this up? Is there a way to configure the OAuth2 flow for this?
    I tried to do custom auth but wasn't sure how to retrieve the code that is sent to the callback after step 1.

Following up here from Retool Office Hours.
Switched this to a custom auth flow.

Step 1 below works successfully.
Step 2 fails (unclear how to extract the code and pass to the next POST request to get the access token)

What happens now, it redirects to the retool oauth page (I put is the redirect URI)

1 Like

Hi @spiritualsystems! This has been trickier to implement than I originally thought, given how close the built-in OAuth2 pattern is to meeting your needs.

I've spent some time trying to rebuild it using a custom pattern but, as you've noticed, there doesn't seem to be a great way to handle the redirect and expose the code to the second step. You could technically build out your own endpoint for handling the redirect but it would be a super hacky implementation and not very tenable.

I think the best path forward is to talk to our dev team about adding some flexibility to the built-in OAuth2 pattern. I'll start that conversation internally and provide an update here as soon as possible. Thanks for your patience!

Thanks @Darren!

Yes, it's ridiculously close to working with both Retool's OAuth2.

Even using the custom auth flow, I almost can get it to work - just no way to capture that code as you're mentioning.


(ignore the actual value for code in there, that was just a test with a hardcoded string)

I'm excited to see your implementation of the workaround & I hope this is an important but small enough change for the team to prioritize!

Again, I truly appreciate the support!

My pleasure - it's been a fun exercise but I'm hoping we can build a more integrated solution before too long. :slightly_smiling_face: :sweat_smile:

I spent some time putting together a proof of concept based on the workaround that we discussed yesterday, which I'll share below. Don't judge me - it's been a while since I did true app development outside of Retool! Here's a recording of it in action. Note that I'm using Google as an example because Pinterest denied my API request.

Right now the actual custom auth as defined in Retool simply redirects to the OAuth2 authorization page. Everything from there is handled by the lightweight server that I put together. It's currently just running on my local machine, so the redirect_uri is a localhost address. You can check out the server code here.

The end result is that the user's access_token gets stored in RetoolDB for later use. I initially wasn't sure how to best associate the token with a particular user, but Google returns an id_token if you ask for the appropriate scope - email, in this case - which sufficed. I would double check Pinterest's documentation to see if they support something similar. They might also allow you to extend the lifetime of the token so that you don't need to re-auth as often.

Last but not least, I put together a quick outline of what it might look like to "schedule" pins and actually post to Pinterest.

This is very much a quick-and-dirty implementation, but you can see that the workflow runs every day at 3pm. I grab all the pins that are scheduled for today from the database, along with necessary user information. Then I just loop through them and hit Pinterest's Create Pin endpoint.

There's obviously a ton you can do to improve this, especially when it comes to error handling. But hopefully it's proof of concept enough to give you a starting point!

Just discovered a feature in Retool Beta that is the exact solution here! @Darren
Toggling this on allowed me to connect Pinterest as a normal Retool OAuth 2 resource.

1 Like