How to obtain the OAuth refresh token for an Add on

237 views
Skip to first unread message

con...@quiteoftenapp.com

unread,
Jun 21, 2020, 4:07:29 PM6/21/20
to Google Apps Script Community
Hello!

Does anyone know how to obtain a refresh token for a G Suite Add on, considering that the authorization flow to obtain the user consent was handled by Apps Script?

I know how to obtain the access token with the method ScriptApp.getOAuthToken(), but I don't know how to obtain the refresh token.

Context:

I have an add on that allows users to schedule recurring meetings. The user grants me access to their calendar when they install the add on, so I can read and write to their calendars when they are running the script.

I want to send them reminders a day before the meeting, so I want to read their calendars in the background using a cloud function when they are not running the script.

In order to do that I would need to have the refresh token for that user since the access token expires.

I'm really stuck on this for many days now. Any help would be much appreciated!

Thanks
Gabriel

Leandro Zubrezki

unread,
Jun 24, 2021, 11:40:47 AM6/24/21
to Google Apps Script Community
Have you found a way? I think the only one is to present the user with the authorization again but with your own OAuth2 flow, and then securely storing the refresh token using KMS or similar.

Frenchcooc FC

unread,
Jun 25, 2021, 9:19:13 AM6/25/21
to Google Apps Script Community
I don't think you can get the OAuth refresh_token through Google Apps Script.
As you mentionned, you can only get the current access_token using ScriptApp.getOAuthToken()

Gabriel Aleixo

unread,
Jun 25, 2021, 9:31:06 AM6/25/21
to google-apps-sc...@googlegroups.com
Hello,
I could not get the refresh token, but you can trigger a new authorization and store the new token to use in your application.
It’s been a while and I stopped developing that app, but I remember I used a library to do that and it wasn’t difficult.

--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/GUKwaCX8vm8/unsubscribe.
To unsubscribe from this group and all its topics, 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/9d289d3d-6f8f-4ba8-afc7-52598c2ea11en%40googlegroups.com.
--
-----
Gabriel Aleixo
Founder & CEO
Reply all
Reply to author
Forward
0 new messages