Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select account in Google App Scripts for users with multiple accounts?

For users that are logged into multiple accounts, how can a script let the user pick an account? For example, Gmail, Google Drive, etc. provide a way for the user to select which account to use with a selectable option on the top-right of the page:

gdrive screenshot

How can developers implement a similar mechanism?

like image 373
Oscar Wahltinez Avatar asked Nov 08 '22 16:11

Oscar Wahltinez


1 Answers

There seems to be no way to do that with Google Apps Script libraries - GAS just uses the current primary account. Also, unfortunately, the API Client Library and thus Google Sign-In for websites don't work inside GAS web apps because of the sandbox frame. You could write your own or use some existing OAuth implementation to authenticate with Google but I found a much much simpler solution using Auth0 Lock with only a Google Connection (using the popup method because the redirect method doesn't work within the sandbox frame).

like image 171
C12Z Avatar answered Nov 14 '22 22:11

C12Z