Search code examples
google-apps-scriptgoogle-apps

Executing Google Apps Scripts on G Suite accounts with 2nd Factor Authentication


I've written a script using an account associated with a normal google gmail account and I had it executing regularly on a G Suite (formally know as Google Apps) Inbox account with out errors or issues for over a year.

I've recently set up the G Suite account with 2nd factor authentication, since this time the script has been failing. My presumption is that 2fa has given the account additional levels of authentication that the script does not have or can not meet.

The failure errors looks as below:

| Start           | Function | Error Message                                     | Trigger    | End             |
|-----------------|----------|---------------------------------------------------|------------|-----------------|
| 1/16/17 1:41 AM | cleanUp  | Authorization is required to perform that action. | time-based | 1/16/17 1:41 AM |

Am I correct? If so how do I allow a script to run on a G Suite Inbox account with 2fa?


Solution

  • This is an interesting scenario. While I have never had the exact same use-case, (a @gmail.com account owning a script which is accessing a G-Suite account), I do have many G-Suite owned Apps Scripts which access accounts that have two factor Authentication enabled.

    Thus, I can confirm it is possible for an Apps Script application to access accounts protected by 2fa.

    My initial guess is that you just need to re-authorise the script from the 2fa protected account, the same way you would have needed to grant it authorisation when you first rolled it out. Typically this would be by opening the script from the 2fa protected account and running any function, to trigger the authorisation dialog.