Refreshing an oauth token in add-on

69 views
Skip to first unread message

Bruce Mcpherson

unread,
Jan 6, 2022, 10:48:00 AM1/6/22
to Google Apps Script Community
It's very convenient to use ScriptApp.getOAuthToken() in an addon to reuse the token from the server side in your client side add-on code. However, these have a limited time to live (1 hour), so what to do if your add on sits around for longer than that? One solution would be to always go for another token every time you needed one, but that would be wasteful. Luckily, there's a way to check a token to see how much life it has, and only get a new one if it's almost expired.


https://ramblings.mcpher.com/apps-script/add-ons/refreshing-oauth/

Kos

unread,
Jan 6, 2022, 11:44:19 AM1/6/22
to Google Apps Script Community
Would it be more efficient just to call script.run and return fresh token with whatever `ScriptApp.getOAuthToken()` have?

Bruce Mcpherson

unread,
Jan 6, 2022, 2:31:53 PM1/6/22
to google-apps-sc...@googlegroups.com
Checking the current token status locally and only bothering getting a new token when required will potentially avoid many unnecessary client to server calls.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/e369868b-1642-40e9-96c4-cf105bfd0aean%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages