How to refresh user access tokens for Google Sheets Add-On?

115 views
Skip to first unread message

Sherif R

unread,
Feb 3, 2025, 4:51:00 PM2/3/25
to Google Apps Script Community
Hello,

Recently I updated the OAuth scopes in my Google Sheets Add-on by removing a restricted scope which I no longer needed and adding a non-sensitive scope in its place.  However my app is now blocked and as far as I understand from a mail I got from the Google Team, I need to revoke the existing user tokens which use the old scope and have the users re-authenticate which will update their tokens with new ones that have the new scope of the Add-on.  These steps are mentioned here in this document

I'm not sure how I'm supposed to revoke the user tokens.  In this document it says to use an HTTP request to the oauth2 end point something like "https://oauth2.googleapis/revoke".  However in AppScript it seems to be this call here "ScriptApp.invalidateAuth();"

So assuming I use this in the onOpen() trigger so that whenever the user launches the app it will revoke authorization and force the user to reauthenticate or Maybe alternatively I can disable and then enable again the APIs in my Cloud console which may also force reauthorization for users who try to login?   If either way works the problem is getting all users or at least the ones with the old tokens to login and use the app.  Some users may not login for a while so they'll still have their old tokens.  As I understand my App will stay blocked until all of the tokens get revoked.  Not sure how to resolve this since it depends on users taking an action which very likely not all of them will do.  Anyone tried this before or any thoughts on how to approach this?

Thanks,
Sherif

Andrew Roberts

unread,
Feb 4, 2025, 2:38:24 PM2/4/25
to google-apps-sc...@googlegroups.com
I added the function checkIfAuthorizationRequired() to my Add-on to force a re-auth (it sends an email if they need to re-auth).

--
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 visit https://groups.google.com/d/msgid/google-apps-script-community/e29020a1-008e-43c3-ae00-3844ddf2ef12n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages