I have a pack that uses Google OAuth but the OAuth token expires very quickly (like 15 to 30 mins). I thought Coda would automatically request a refresh token if there was a 401 returned but that’s not happening and instead the pack fails to refresh the table with an error once the token expires and I have to resign/auth to Google to refresh the table.
According to the Coda refresh docs I thought that would trigger a automatic refresh behind the screnes but it’s not. So I added a try/catch that is suggested in the docs but nothing.
Your OAuth flow didn’t return a refresh_token. Every API has different rules as to when these are returned or not. For Google OAuth it requires specifying the access_type and prompt query parameters as shown in this code sample: API setup samples - Coda Pack SDK.
Your code is swallowing the 401 error. We only attempt a refresh of the access token when the Pack throws a 401 StatusCodeError. If you have a try/catch that is handling these in some other way (logging them, throwing a different error type, etc) then the refresh won’t be attempted. You can read more about that here: Authenticating using OAuth - Coda Pack SDK
Check to see if either of those could be affecting your Pack, and let me know what you find.
I actually do have the additional params for Google (accidentally deleted it when streamlining the code in the post). I originally too the code directly from the link you posted.
Hmm, those are the usual suspects. If you share the doc with support and then send me the link I can take a look at the logs and see if anything jumps out.
Thanks for sharing. The internal error states that it couldn’t find a refresh_token, and looking at the responses from the OAuth flow there indeed is none being returned. Looking at your code more closely, I think this may be the issue:
token_access_type: "offline",
As per the sample code I pointed to, it should be: