What's the best way to get the refresh token?

550 views
Skip to first unread message

N A

unread,
Oct 4, 2022, 5:41:14 AM10/4/22
to Google Apps Script Community
For Google Workspace Add-on, what's the best way to get the refresh token?

N A

unread,
Oct 4, 2022, 5:52:59 AM10/4/22
to Google Apps Script Community
In my Apps Script, I can grab the access token via getOAuthToken() and pass it to my server via UrlFetchApp. The issue is the access token expires in a few minutes. What I want is to be able to refresh the access token.

So, my solution is to re-authenticate the user in my server which works but it's a redundant solution because user is first authenticated after installing the addon, then, on the website, I re-authenticate the user again.

What do you think?

Messi Jini

unread,
Oct 5, 2022, 8:38:32 AM10/5/22
to Google Apps Script Community
I am also new to this...  Just wondering , is this an issue because session time out?  Then We have to increase the session expiry settings. 

Flores Pablo Maria Sanguinetti

unread,
Oct 5, 2022, 8:55:13 AM10/5/22
to google-apps-sc...@googlegroups.com
Hi! Developers

At the end of developing a WEBAPP, try to record the email in the spreadsheet from the run of each user.
var email = Session.getActiveUser().getEmail();
Logger.log(email);

Use as permissions ;

"oauthScopes": [
     "https://www.googleapis.com/auth/spreadsheets",
     "https://www.googleapis.com/auth/userinfo.email"
   ],

inside apps script.json

When I run the parameters through the do post method, the only one that gives me a null value in the console is email .

can anybody help me?

Thank you very much !
 

Pablo!

--
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/87dccf96-0bb6-4385-a5e4-87eb5f06972cn%40googlegroups.com.

N A

unread,
Oct 6, 2022, 9:32:48 PM10/6/22
to Google Apps Script Community
Just an update, the access_token expires in one (1) hour. I can confirm that there's no other solution other than re-authorizing.

N A

unread,
Oct 6, 2022, 9:33:17 PM10/6/22
to Google Apps Script Community
Hi Messij, no, we don't have control on session expiry settings.

N A

unread,
Oct 6, 2022, 9:40:35 PM10/6/22
to Google Apps Script Community
Hi Pablo!

The question is unrelated to refresh_token. However, I'll try to answer your question.

I haven't tried this in a WebApp but here's a helpful link ( https://github.com/tanaikech/taking-advantage-of-Web-Apps-with-google-apps-script#authorization-for-scopes ) I think you can do this with the proper permissions.

Hope that helps.


On Wednesday, October 5, 2022 at 8:55:13 PM UTC+8 fsan...@agro.uba.ar wrote:

Andrew Roberts

unread,
Oct 7, 2022, 2:23:41 AM10/7/22
to google-apps-sc...@googlegroups.com
Could you use the Google Apps Script OAuth2 library to get the token? I understand it automatically refreshes the token.

DimuDesigns

unread,
Oct 7, 2022, 11:45:06 AM10/7/22
to Google Apps Script Community
It is NOT possible to retrieve the refresh token of an App Script application. Apps Script projects are automatically generated and internally managed by Google, and as far as OAuth goes, they only expose access tokens via the ScriptApp built-in service.

If you plan on making your Add-on publicly available, then be aware that passing an end-user's access token that uses restricted scopes (Gmail, Drive, etc.) to a 3rd-party server will likely trigger a security assessment which will run you anywhere from US$10,000.00 to US$75,000.00 annually.

See Google's support docs for more information:
https://support.google.com/cloud/answer/9110914?hl=en#zippy=%2Csecurity-assessment
Reply all
Reply to author
Forward
0 new messages