Hi all,
I wondered if I could get some advice on how to best handle OAuth access and refresh tokens.
I have built some Zaps which make calls to an API using Webhook by Zapier. The calls must be authenticated with an access token. An access token is valid for 30 minutes and can be refreshed using the refresh token, which is valid for 60 days.
I store the access and refresh tokens in a Zapier Table. I have built a Sub-Zap to refresh the token, which essentially fetches the refresh token from the table, refreshes it, updates the table, and passes the access token through to the Zap that called it.
This works well, but the trouble is that because multiple Zaps are using it, there’s the risk that another Zap calls the Sub-Zap before the first Zap has finished, making the first access token invalid.
I thought about having the Sub-Zap refresh the token every 30 minutes, but this would seem a waste of tasks as the Zaps which need the token don’t run all that frequently.
So I was wondering, does anyone have a good solution for this? I was thinking about maybe recording the expiry date/time and somehow refreshing based on this.
Any advice would be very much appreciated.
Thanks,
Seb